🪢 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
fix(otel): override span observation types if generation-like attributes present (#8683)
Hassieb Pakzaddff54e8ba9a6
diff --git a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts b/web/src/__tests__/server/api/otel/otelMapping.servertest.tsindex 99b57453ec..486294467b 100644--- a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts+++ b/web/src/__tests__/server/api/otel/otelMapping.servertest.ts@@ -3851,5 +3851,67 @@ describe("OTel Resource Span Mapping", () => {const traceEvents = events.filter((e) => e.type === "trace-create");expect(traceEvents.length).toBe(1);});++ it("should override the observation type if it is declared as 'span' but holds generation-like attributes", async () => {+ // Issue: https://github.com/langfuse/langfuse/issues/8682+ const otelSpans = [+ {+ resource: { attributes: [] },+ scopeSpans: [+ {+ scope: { name: "test-scope" },+ spans: [+ {+ traceId: {+ data: [+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,+ ],+ },+ spanId: {+ data: [1, 2, 3, 4, 5, 6, 7, 8],+ },+ name: "unknown-operation",+ startTimeUnixNano: 1000000000,+ endTimeUnixNano: 2000000000,+ attributes: [+ // No openinference.span.kind, no model indicators, no explicit type+ {+ key: "langfuse.observation.type",+ value: { stringValue: "span" },+ },+ {+ key: "langfuse.observation.model.name",+ value: { stringValue: "gpt-4o" },+ },+ ],+ status: {},+ },+ ],+ },+ ],+ },+ ];++ const events = await convertOtelSpanToIngestionEvent(+ otelSpans[0],+ new Set(),+ publicKey,+ );++ // Should create a span-create event (default when no mapping found)+ const spanEvents = events.filter((e) => e.type === "generation-create");+ expect(spanEvents.length).toBe(1);+ expect(spanEvents[0].body.name).toBe("unknown-operation");++ // Should not create any span-create or other typed events+ const nonSpanEvents = events.filter(+ (e) => e.type !== "generation-create" && e.type !== "trace-create",+ );+ expect(nonSpanEvents.length).toBe(0);++ // Should still create a trace+ const traceEvents = events.filter((e) => e.type === "trace-create");+ expect(traceEvents.length).toBe(1);+ });});});diff --git a/web/src/features/otel/server/OtelIngestionProcessor.ts b/web/src/features/otel/server/OtelIngestionProcessor.tsindex 7b3292f36e..3a7b6a9aec 100644--- a/web/src/features/otel/server/OtelIngestionProcessor.ts+++ b/web/src/features/otel/server/OtelIngestionProcessor.ts@@ -645,6 +645,27 @@ export class OtelIngestionProcessor {LangfuseOtelSpanAttributes.OBSERVATION_TYPE] as string;+ // If generation-like attributes are set even though observation type is span, override to 'generation'+ // Issue: https://github.com/langfuse/langfuse/issues/8682+ // Affected SDK versions: Python SDK <= 3.3.0+ const hasGenerationAttributes = Object.keys(attributes).some((key) => {+ const generationKeys: LangfuseOtelSpanAttributes[] = [+ LangfuseOtelSpanAttributes.OBSERVATION_MODEL,+ LangfuseOtelSpanAttributes.OBSERVATION_COST_DETAILS,+ LangfuseOtelSpanAttributes.OBSERVATION_USAGE_DETAILS,+ LangfuseOtelSpanAttributes.OBSERVATION_COMPLETION_START_TIME,+ LangfuseOtelSpanAttributes.OBSERVATION_MODEL_PARAMETERS,+ LangfuseOtelSpanAttributes.OBSERVATION_PROMPT_NAME,+ LangfuseOtelSpanAttributes.OBSERVATION_PROMPT_VERSION,+ ];++ return generationKeys.includes(key as any);+ });++ if (observationType === "span" && hasGenerationAttributes) {+ observationType = "generation";+ }+// If no explicit observation type, try mapping from various frameworksif (!observationType) {const mappedType = observationTypeMapper.mapToObservationType(attributes);