Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(evals): emit code eval dispatch duration distribution metric (#15071)

Tobias Wochinger93f8c77d084a
diff --git a/packages/shared/src/server/evals/awsLambdaCodeEvalDispatcher.test.ts b/packages/shared/src/server/evals/awsLambdaCodeEvalDispatcher.test.ts
index 3bdaca21bc..c905a5c2c0 100644
--- a/packages/shared/src/server/evals/awsLambdaCodeEvalDispatcher.test.ts
+++ b/packages/shared/src/server/evals/awsLambdaCodeEvalDispatcher.test.ts
@@ -12,12 +12,14 @@ const mocks = vi.hoisted(() => {
return {
span,
instrumentAsync: vi.fn(async (_ctx, callback) => callback(span)),
+ recordDistribution: vi.fn(),
traceException: vi.fn(),
};
});
vi.mock("../instrumentation", () => ({
instrumentAsync: mocks.instrumentAsync,
+ recordDistribution: mocks.recordDistribution,
traceException: mocks.traceException,
}));
@@ -52,6 +54,18 @@ function expectSpanAttributes(attributes: Record<string, unknown>): void {
);
}
+function expectDispatchDurationRecorded(): void {
+ expect(mocks.recordDistribution).toHaveBeenCalledExactlyOnceWith(
+ "langfuse.code_eval.dispatch_duration",
+ expect.any(Number),
+ {
+ project_id: "project-1",
+ language: "TYPESCRIPT",
+ unit: "milliseconds",
+ },
+ );
+}
+
describe("AwsLambdaCodeEvalDispatcher observability", () => {
beforeEach(() => {
vi.clearAllMocks();
@@ -107,6 +121,7 @@ describe("AwsLambdaCodeEvalDispatcher observability", () => {
"aws.sdk.attempts": 2,
"aws.sdk.total_retry_delay_ms": 15,
});
+ expectDispatchDurationRecorded();
});
it("records the original AWS SDK error before throwing the derived dispatcher error", async () => {
@@ -146,6 +161,7 @@ describe("AwsLambdaCodeEvalDispatcher observability", () => {
"aws.sdk.attempts": 3,
"aws.sdk.total_retry_delay_ms": 25,
});
+ expectDispatchDurationRecorded();
});
it("records dispatch context and error code for preflight limit failures", async () => {
diff --git a/packages/shared/src/server/evals/awsLambdaCodeEvalDispatcher.ts b/packages/shared/src/server/evals/awsLambdaCodeEvalDispatcher.ts
index 27ba961d08..89ae98f49d 100644
--- a/packages/shared/src/server/evals/awsLambdaCodeEvalDispatcher.ts
+++ b/packages/shared/src/server/evals/awsLambdaCodeEvalDispatcher.ts
@@ -5,7 +5,11 @@ import {
} from "@aws-sdk/client-lambda";
import { SpanKind, type AttributeValue, type Span } from "@opentelemetry/api";
import { z } from "zod";
-import { instrumentAsync, traceException } from "../instrumentation";
+import {
+ instrumentAsync,
+ recordDistribution,
+ traceException,
+} from "../instrumentation";
import { logger } from "../logger";
import {
assertDispatchInputWithinLimits,
@@ -171,7 +175,25 @@ export class AwsLambdaCodeEvalDispatcher implements CodeEvalDispatcher {
traceScope: "code-eval-dispatcher",
startNewTrace: true,
},
- async (span) => this.dispatchWithTracing(input, span),
+ async (span) => {
+ // Dispatch spans are ingestion-sampled, so fleet-slowness monitors
+ // (per-project p95 quorum) run on this unsampled distribution instead.
+ // Recorded on failures too: timeouts are the slow runs that matter most.
+ const startTime = Date.now();
+ try {
+ return await this.dispatchWithTracing(input, span);
+ } finally {
+ recordDistribution(
+ "langfuse.code_eval.dispatch_duration",
+ Date.now() - startTime,
+ {
+ project_id: input.scope.projectId,
+ language: input.runtime.language,
+ unit: "milliseconds",
+ },
+ );
+ }
+ },
);
}