🪢 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: Add gen_ai.conversation.id support (#7738)
Marc Klingenc2a0b381d4b5
diff --git a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts b/web/src/__tests__/server/api/otel/otelMapping.servertest.tsindex a7c80ca960..c657967b1f 100644--- a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts+++ b/web/src/__tests__/server/api/otel/otelMapping.servertest.ts@@ -1274,6 +1274,16 @@ describe("OTel Resource Span Mapping", () => {entityAttributeValue: "session-1",},],+ [+ "should extract sessionId on trace from gen_ai.conversation.id",+ {+ entity: "trace",+ otelAttributeKey: "gen_ai.conversation.id",+ otelAttributeValue: { stringValue: "conversation-1" },+ entityAttributeKey: "sessionId",+ entityAttributeValue: "conversation-1",+ },+ ],["should extract providedModelName from gen_ai.request.model",{@@ -3149,5 +3159,153 @@ describe("OTel Resource Span Mapping", () => {expect(spanEvents[0].body.name).toBe("child-span");expect(spanEvents[1].body.name).toBe("root-span");});++ it("should prioritize langfuse.session.id over gen_ai.conversation.id when both are present", async () => {+ const otelSpans = [+ {+ resource: {+ attributes: [+ {+ key: "service.name",+ value: { stringValue: "test-service" },+ },+ ],+ },+ scopeSpans: [+ {+ scope: {+ name: "test-scope",+ version: "1.0.0",+ },+ spans: [+ {+ traceId: {+ type: "Buffer",+ data: [+ 149, 243, 185, 38, 199, 208, 9, 146, 91, 203, 93, 188, 39,+ 49, 17, 32,+ ],+ },+ spanId: {+ type: "Buffer",+ data: [212, 62, 55, 183, 209, 126, 84, 118],+ },+ name: "root-span",+ kind: 1,+ startTimeUnixNano: {+ low: 1047784088,+ high: 406627672,+ unsigned: true,+ },+ endTimeUnixNano: {+ low: 1149405088,+ high: 406627672,+ unsigned: true,+ },+ attributes: [+ {+ key: "langfuse.session.id",+ value: { stringValue: "langfuse-session-123" },+ },+ {+ key: "gen_ai.conversation.id",+ value: { stringValue: "otel-conversation-456" },+ },+ ],+ status: {},+ },+ ],+ },+ ],+ },+ ];++ const events = (+ await Promise.all(+ otelSpans.map(+ async (span) =>+ await convertOtelSpanToIngestionEvent(span, new Set(), publicKey),+ ),+ )+ ).flat();++ const traceEvent = events.find((e) => e.type === "trace-create");+ expect(traceEvent).toBeDefined();+ expect(traceEvent.body.sessionId).toBe("langfuse-session-123");+ });++ it("should prioritize session.id over gen_ai.conversation.id when both are present", async () => {+ const otelSpans = [+ {+ resource: {+ attributes: [+ {+ key: "service.name",+ value: { stringValue: "test-service" },+ },+ ],+ },+ scopeSpans: [+ {+ scope: {+ name: "test-scope",+ version: "1.0.0",+ },+ spans: [+ {+ traceId: {+ type: "Buffer",+ data: [+ 149, 243, 185, 38, 199, 208, 9, 146, 91, 203, 93, 188, 39,+ 49, 17, 32,+ ],+ },+ spanId: {+ type: "Buffer",+ data: [212, 62, 55, 183, 209, 126, 84, 118],+ },+ name: "root-span",+ kind: 1,+ startTimeUnixNano: {+ low: 1047784088,+ high: 406627672,+ unsigned: true,+ },+ endTimeUnixNano: {+ low: 1149405088,+ high: 406627672,+ unsigned: true,+ },+ attributes: [+ {+ key: "session.id",+ value: { stringValue: "session-id-123" },+ },+ {+ key: "gen_ai.conversation.id",+ value: { stringValue: "otel-conversation-456" },+ },+ ],+ status: {},+ },+ ],+ },+ ],+ },+ ];++ const events = (+ await Promise.all(+ otelSpans.map(+ async (span) =>+ await convertOtelSpanToIngestionEvent(span, new Set(), publicKey),+ ),+ )+ ).flat();++ const traceEvent = events.find((e) => e.type === "trace-create");+ expect(traceEvent).toBeDefined();+ expect(traceEvent.body.sessionId).toBe("session-id-123");+ });});});diff --git a/web/src/features/otel/server/OtelIngestionProcessor.ts b/web/src/features/otel/server/OtelIngestionProcessor.tsindex c5f9706ebe..3e6e903e8b 100644--- a/web/src/features/otel/server/OtelIngestionProcessor.ts+++ b/web/src/features/otel/server/OtelIngestionProcessor.ts@@ -1044,6 +1044,7 @@ export class OtelIngestionProcessor {const userIdKeys = ["langfuse.session.id","session.id",+ "gen_ai.conversation.id",`${LangfuseOtelSpanAttributes.OBSERVATION_METADATA}.langfuse_session_id`,`${LangfuseOtelSpanAttributes.TRACE_METADATA}.langfuse_session_id`,];