🪢 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(ingestion): drop mapped Langfuse attributes from AI gateway metadata (#17955)
Hassieb Pakzaddad948a3b7e9
diff --git a/ai-gateway/README.md b/ai-gateway/README.mdindex 5d84a98d69..8091da4ac9 100644--- a/ai-gateway/README.md+++ b/ai-gateway/README.md@@ -384,9 +384,9 @@ historical traces are not rewritten.headers arrive. After headers arrive it retains the relayed status, even if astream subsequently fails; cancellation before headers leaves the status unknown.Relay outcome, provider status, completeness flags and first-byte timing remain-internal facts rather than generation metadata. Ingestion removes mapped observation-attribute-duplicates for the gateway scope while preserving custom attributes, scope and-resources.+internal facts rather than generation metadata. For the gateway scope, ingestion removes+Langfuse attributes already mapped to trace and observation fields, such as user, session,+trace name, tags and environment, while preserving custom attributes, scope and resources.Provider HTTP failures and failed SSE responses set the generation level to `ERROR`with the available HTTP status in its status message. Full mode also includes adiff --git a/packages/shared/src/server/otel/OtelIngestionProcessor.metadataDropped.test.ts b/packages/shared/src/server/otel/OtelIngestionProcessor.metadataDropped.test.tsindex ab945c3910..06039eedac 100644--- a/packages/shared/src/server/otel/OtelIngestionProcessor.metadataDropped.test.ts+++ b/packages/shared/src/server/otel/OtelIngestionProcessor.metadataDropped.test.ts@@ -126,7 +126,7 @@ describe("gateway metadata", () => {["v3", "other-instrumentation"],["v4", "other-instrumentation"],])(- "preserves canonical fields and metadata for %s %s",+ "preserves canonical fields and non-duplicate metadata for %s %s",async (path, scope) => {const completionStartTime = "2025-07-13T05:20:00.500Z";const modelParameters = {@@ -145,6 +145,11 @@ describe("gateway metadata", () => {"langfuse.observation.usage_details": JSON.stringify(usageDetails),"langfuse.observation.cost_details": JSON.stringify({ total: 0.001 }),"langfuse.observation.completion_start_time": completionStartTime,+ "user.id": "user-test",+ "session.id": "session-test",+ "langfuse.trace.name": "trace-test",+ "langfuse.trace.tags": JSON.stringify(["tag-a", "tag-b"]),+ "langfuse.environment": "staging",};const batch = buildBatch(Object.entries({@@ -178,11 +183,16 @@ describe("gateway metadata", () => {reasoning: '{"effort":"low"}',},completionStartTime,+ environment: "staging",input: '[{"role":"user","content":"Hi"}]',output: '[{"type":"message","content":[]}]',...(path === "v4"? {type: "GENERATION",+ userId: "user-test",+ sessionId: "session-test",+ traceName: "trace-test",+ tags: ["tag-a", "tag-b"],modelName: "test-model",providedUsageDetails: usageDetails,providedCostDetails: { total: 0.001 },diff --git a/packages/shared/src/server/otel/OtelIngestionProcessor.ts b/packages/shared/src/server/otel/OtelIngestionProcessor.tsindex 667f58277b..b0f3f4942f 100644--- a/packages/shared/src/server/otel/OtelIngestionProcessor.ts+++ b/packages/shared/src/server/otel/OtelIngestionProcessor.ts@@ -1891,13 +1891,12 @@ export class OtelIngestionProcessor {delete rawFilteredAttributes[key];});- // Gateway observation attributes are represented by canonical fields.- // Keep unknown attributes available for diagnostics.+ // Gateway spans only use known Langfuse attributes for values that are+ // represented by canonical trace and observation fields. Keep unknown+ // attributes available for diagnostics.if (instrumentationScopeName === "langfuse-ai-gateway") {for (const key of Object.values(LangfuseOtelSpanAttributes)) {- if (key.startsWith("langfuse.observation.")) {- delete rawFilteredAttributes[key];- }+ delete rawFilteredAttributes[key];}}