🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(ingestion): measure overflow processing duration (#15654)
Hassieb Pakzada6ed0461a41b
diff --git a/worker/src/features/observation-field-overflow/processObservationFieldOverflow.test.ts b/worker/src/features/observation-field-overflow/processObservationFieldOverflow.test.tsindex 72a3fb5af7..2c65d9e3de 100644--- a/worker/src/features/observation-field-overflow/processObservationFieldOverflow.test.ts+++ b/worker/src/features/observation-field-overflow/processObservationFieldOverflow.test.ts@@ -147,6 +147,10 @@ describe("applyObservationFieldOverflow", () => {Buffer.byteLength(mediaReference("output-media")) -Buffer.byteLength(mediaReference("metadata-media")),});+ expect(mocks.recordDistribution).toHaveBeenCalledWith(+ "langfuse.ingestion.observation_field_overflow.processing_duration_ms",+ expect.any(Number),+ );});it("applies the limit to each metadata value rather than their aggregate size", async () => {@@ -323,6 +327,10 @@ describe("applyObservationFieldOverflow", () => {outputUpload.resolve({ mediaId: "output-media", outcome: "uploaded" });await expect(resultPromise).resolves.toBe(eventRecord);+ expect(mocks.recordDistribution).toHaveBeenCalledWith(+ "langfuse.ingestion.observation_field_overflow.processing_duration_ms",+ expect.any(Number),+ );expect(mocks.logger.warn).toHaveBeenCalledWith("Observation field overflow processing failed; persisting original record",{diff --git a/worker/src/features/observation-field-overflow/processObservationFieldOverflow.ts b/worker/src/features/observation-field-overflow/processObservationFieldOverflow.tsindex 95666c0089..65f395579c 100644--- a/worker/src/features/observation-field-overflow/processObservationFieldOverflow.ts+++ b/worker/src/features/observation-field-overflow/processObservationFieldOverflow.ts@@ -54,39 +54,48 @@ export async function applyObservationFieldOverflow(name: "langfuse.ingestion.observation_field_overflow.process",},async (span) => {- const results = await uploadOverflowCandidates(- eventRecord,- candidates,- mediaBucket,- );+ const startedAt = Date.now();- span.setAttributes({- "langfuse.project.id": eventRecord.project_id,- "langfuse.trace.id": eventRecord.trace_id,- "langfuse.observation.id": eventRecord.span_id,- "langfuse.ingestion.observation_field_overflow.candidates":- candidates.length,- "langfuse.ingestion.observation_field_overflow.fields":- candidates.map(({ field }) => field),- "langfuse.ingestion.observation_field_overflow.uploaded":- results.filter(({ outcome }) => outcome === "uploaded").length,- "langfuse.ingestion.observation_field_overflow.reused":- results.filter(({ outcome }) => outcome === "reused").length,- "langfuse.ingestion.observation_field_overflow.failed":- results.filter(({ outcome }) => outcome === "failed").length,- "langfuse.ingestion.observation_field_overflow.bytes_processed":- candidates.reduce(- (total, { originalBytes }) => total + originalBytes,- 0,- ),- "langfuse.ingestion.observation_field_overflow.bytes_removed":- results.reduce(- (total, { bytesRemoved }) => total + bytesRemoved,- 0,- ),- });+ try {+ const results = await uploadOverflowCandidates(+ eventRecord,+ candidates,+ mediaBucket,+ );- return applyOverflowResults(eventRecord, results);+ span.setAttributes({+ "langfuse.project.id": eventRecord.project_id,+ "langfuse.trace.id": eventRecord.trace_id,+ "langfuse.observation.id": eventRecord.span_id,+ "langfuse.ingestion.observation_field_overflow.candidates":+ candidates.length,+ "langfuse.ingestion.observation_field_overflow.fields":+ candidates.map(({ field }) => field),+ "langfuse.ingestion.observation_field_overflow.uploaded":+ results.filter(({ outcome }) => outcome === "uploaded").length,+ "langfuse.ingestion.observation_field_overflow.reused":+ results.filter(({ outcome }) => outcome === "reused").length,+ "langfuse.ingestion.observation_field_overflow.failed":+ results.filter(({ outcome }) => outcome === "failed").length,+ "langfuse.ingestion.observation_field_overflow.bytes_processed":+ candidates.reduce(+ (total, { originalBytes }) => total + originalBytes,+ 0,+ ),+ "langfuse.ingestion.observation_field_overflow.bytes_removed":+ results.reduce(+ (total, { bytesRemoved }) => total + bytesRemoved,+ 0,+ ),+ });++ return applyOverflowResults(eventRecord, results);+ } finally {+ recordDistribution(+ "langfuse.ingestion.observation_field_overflow.processing_duration_ms",+ Date.now() - startedAt,+ );+ }},);} catch (error) {