Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .claude/settings.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@
"WebFetch(domain:docs.stripe.com)",
"WebFetch(domain:ai.google.dev)",
"Bash(npx tsoa:*)",
"Bash(python3:*)"
"Bash(python3:*)",
"Bash(npx eslint:*)",
"Bash(./run_all_workers.sh:*)"
],
"deny": []
},
Expand Down
8 changes: 2 additions & 6 deletions bifrost/lib/clients/jawnTypes/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1790,10 +1790,6 @@ Json: JsonObject;
gt?: string;
};
/** @description Make all properties in T optional */
Partial_VectorOperators_: {
contains?: string;
};
/** @description Make all properties in T optional */
Partial_RequestResponseRMTToOperators_: {
country_code?: components["schemas"]["Partial_TextOperators_"];
latency?: components["schemas"]["Partial_NumberOperators_"];
Expand Down Expand Up @@ -1829,8 +1825,8 @@ Json: JsonObject;
[key: string]: components["schemas"]["Partial_TextOperators_"];
};
scores_column?: components["schemas"]["Partial_TextOperators_"];
request_body?: components["schemas"]["Partial_VectorOperators_"];
response_body?: components["schemas"]["Partial_VectorOperators_"];
request_body?: components["schemas"]["Partial_TextOperators_"];
response_body?: components["schemas"]["Partial_TextOperators_"];
cache_enabled?: components["schemas"]["Partial_BooleanOperators_"];
cache_reference_id?: components["schemas"]["Partial_TextOperators_"];
cached?: components["schemas"]["Partial_BooleanOperators_"];
Expand Down
8 changes: 2 additions & 6 deletions bifrost/lib/clients/jawnTypes/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1871,10 +1871,6 @@ Json: JsonObject;
gt?: string;
};
/** @description Make all properties in T optional */
Partial_VectorOperators_: {
contains?: string;
};
/** @description Make all properties in T optional */
Partial_RequestResponseRMTToOperators_: {
country_code?: components["schemas"]["Partial_TextOperators_"];
latency?: components["schemas"]["Partial_NumberOperators_"];
Expand Down Expand Up @@ -1910,8 +1906,8 @@ Json: JsonObject;
[key: string]: components["schemas"]["Partial_TextOperators_"];
};
scores_column?: components["schemas"]["Partial_TextOperators_"];
request_body?: components["schemas"]["Partial_VectorOperators_"];
response_body?: components["schemas"]["Partial_VectorOperators_"];
request_body?: components["schemas"]["Partial_TextOperators_"];
response_body?: components["schemas"]["Partial_TextOperators_"];
cache_enabled?: components["schemas"]["Partial_BooleanOperators_"];
cache_reference_id?: components["schemas"]["Partial_TextOperators_"];
cached?: components["schemas"]["Partial_BooleanOperators_"];
Expand Down
13 changes: 2 additions & 11 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4036,15 +4036,6 @@
"type": "object",
"description": "Make all properties in T optional"
},
"Partial_VectorOperators_": {
"properties": {
"contains": {
"type": "string"
}
},
"type": "object",
"description": "Make all properties in T optional"
},
"Partial_RequestResponseRMTToOperators_": {
"properties": {
"country_code": {
Expand Down Expand Up @@ -4146,10 +4137,10 @@
"$ref": "#/components/schemas/Partial_TextOperators_"
},
"request_body": {
"$ref": "#/components/schemas/Partial_VectorOperators_"
"$ref": "#/components/schemas/Partial_TextOperators_"
},
"response_body": {
"$ref": "#/components/schemas/Partial_VectorOperators_"
"$ref": "#/components/schemas/Partial_TextOperators_"
},
"cache_enabled": {
"$ref": "#/components/schemas/Partial_BooleanOperators_"
Expand Down
8 changes: 2 additions & 6 deletions helicone-mcp/src/types/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1871,10 +1871,6 @@ Json: JsonObject;
gt?: string;
};
/** @description Make all properties in T optional */
Partial_VectorOperators_: {
contains?: string;
};
/** @description Make all properties in T optional */
Partial_RequestResponseRMTToOperators_: {
country_code?: components["schemas"]["Partial_TextOperators_"];
latency?: components["schemas"]["Partial_NumberOperators_"];
Expand Down Expand Up @@ -1910,8 +1906,8 @@ Json: JsonObject;
[key: string]: components["schemas"]["Partial_TextOperators_"];
};
scores_column?: components["schemas"]["Partial_TextOperators_"];
request_body?: components["schemas"]["Partial_VectorOperators_"];
response_body?: components["schemas"]["Partial_VectorOperators_"];
request_body?: components["schemas"]["Partial_TextOperators_"];
response_body?: components["schemas"]["Partial_TextOperators_"];
cache_enabled?: components["schemas"]["Partial_BooleanOperators_"];
cache_reference_id?: components["schemas"]["Partial_TextOperators_"];
cached?: components["schemas"]["Partial_BooleanOperators_"];
Expand Down
8 changes: 2 additions & 6 deletions web/lib/clients/jawnTypes/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1790,10 +1790,6 @@ Json: JsonObject;
gt?: string;
};
/** @description Make all properties in T optional */
Partial_VectorOperators_: {
contains?: string;
};
/** @description Make all properties in T optional */
Partial_RequestResponseRMTToOperators_: {
country_code?: components["schemas"]["Partial_TextOperators_"];
latency?: components["schemas"]["Partial_NumberOperators_"];
Expand Down Expand Up @@ -1829,8 +1825,8 @@ Json: JsonObject;
[key: string]: components["schemas"]["Partial_TextOperators_"];
};
scores_column?: components["schemas"]["Partial_TextOperators_"];
request_body?: components["schemas"]["Partial_VectorOperators_"];
response_body?: components["schemas"]["Partial_VectorOperators_"];
request_body?: components["schemas"]["Partial_TextOperators_"];
response_body?: components["schemas"]["Partial_TextOperators_"];
cache_enabled?: components["schemas"]["Partial_BooleanOperators_"];
cache_reference_id?: components["schemas"]["Partial_TextOperators_"];
cached?: components["schemas"]["Partial_BooleanOperators_"];
Expand Down
8 changes: 2 additions & 6 deletions web/lib/clients/jawnTypes/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1871,10 +1871,6 @@ Json: JsonObject;
gt?: string;
};
/** @description Make all properties in T optional */
Partial_VectorOperators_: {
contains?: string;
};
/** @description Make all properties in T optional */
Partial_RequestResponseRMTToOperators_: {
country_code?: components["schemas"]["Partial_TextOperators_"];
latency?: components["schemas"]["Partial_NumberOperators_"];
Expand Down Expand Up @@ -1910,8 +1906,8 @@ Json: JsonObject;
[key: string]: components["schemas"]["Partial_TextOperators_"];
};
scores_column?: components["schemas"]["Partial_TextOperators_"];
request_body?: components["schemas"]["Partial_VectorOperators_"];
response_body?: components["schemas"]["Partial_VectorOperators_"];
request_body?: components["schemas"]["Partial_TextOperators_"];
response_body?: components["schemas"]["Partial_TextOperators_"];
cache_enabled?: components["schemas"]["Partial_BooleanOperators_"];
cache_reference_id?: components["schemas"]["Partial_TextOperators_"];
cached?: components["schemas"]["Partial_BooleanOperators_"];
Expand Down
38 changes: 38 additions & 0 deletions worker/src/lib/HeliconeProxyRequest/ProxyForwarder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import {
checkRateLimit as checkRateLimitDO,
updateRateLimitCounter as updateRateLimitCounterDO,
} from "../clients/DurableObjectRateLimiterClient";
import {
createDataDogTracer,
DataDogTracer,
TraceContext,
} from "../monitoring/DataDogTracer";

import { HeliconeProducer } from "../clients/producers/HeliconeProducer";
import { checkPromptSecurity } from "../clients/PromptSecurityClient";
Expand Down Expand Up @@ -59,6 +64,14 @@ export async function proxyForwarder(
}
const responseBuilder = new ResponseBuilder();

// Create DataDog tracer for rate limit monitoring
const tracer = createDataDogTracer(env);
const traceContext = tracer.startTrace(
"proxy.rate_limit",
`${provider}:${request.url.pathname}`,
{ provider }
);

const { data: cacheSettings, error: cacheError } = getCacheSettings(
proxyRequest.requestWrapper.getHeaders()
);
Expand Down Expand Up @@ -112,6 +125,8 @@ export async function proxyForwarder(
ctx,
rateLimited,
response.status,
tracer,
traceContext,
"false", // S3_ENABLED
cachedResponse,
cacheSettings
Expand Down Expand Up @@ -150,6 +165,11 @@ export async function proxyForwarder(
}

if (finalRateLimitOptions) {
// Set org_id on tracer for correlation
if (traceContext?.sampled) {
tracer.setOrgId(orgData.organizationId);
}

try {
const rateLimitCheckResult = await checkRateLimitDO({
organizationId: orgData.organizationId,
Expand All @@ -158,6 +178,8 @@ export async function proxyForwarder(
rateLimitOptions: finalRateLimitOptions,
userId: proxyRequest.userId,
cost: 1,
tracer,
traceContext,
});
responseBuilder.addRateLimitHeaders(
rateLimitCheckResult,
Expand Down Expand Up @@ -235,6 +257,8 @@ export async function proxyForwarder(
ctx,
rateLimited,
response.status,
tracer,
traceContext,
undefined,
undefined,
undefined
Expand Down Expand Up @@ -306,6 +330,8 @@ export async function proxyForwarder(
ctx,
rateLimited,
moderationRes.response?.status ?? 500,
tracer,
traceContext,
undefined,
undefined,
undefined
Expand Down Expand Up @@ -402,6 +428,8 @@ export async function proxyForwarder(
ctx,
rateLimited,
response.status,
tracer,
traceContext,
undefined,
undefined,
undefined
Expand Down Expand Up @@ -448,6 +476,8 @@ async function log(
ctx: ExecutionContext,
rateLimited: boolean,
statusCode: number,
tracer: DataDogTracer,
traceContext: TraceContext | null,
S3_ENABLED?: Env["S3_ENABLED"],
cachedResponse?: Response,
cacheSettings?: CacheSettings
Expand Down Expand Up @@ -667,9 +697,17 @@ async function log(
rateLimitOptions: finalRateLimitOptions,
userId: proxyRequest.userId,
cost: costInCents,
tracer,
traceContext,
});
}
}

// Finish trace and send to DataDog
if (tracer && traceContext?.sampled) {
tracer.finishTrace({ rate_limited: rateLimited.toString() });
await tracer.sendTrace();
}
})
.catch((error) => {
console.error("Error in response processing chain:", error);
Expand Down
Loading
Loading