Skip to content

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

fix(otel): fix event metadata scope missing (#12633)

Nimar3d9621a3769f
diff --git a/packages/shared/src/server/otel/OtelIngestionProcessor.ts b/packages/shared/src/server/otel/OtelIngestionProcessor.ts
index 0eb0366426..224d33b94e 100644
--- a/packages/shared/src/server/otel/OtelIngestionProcessor.ts
+++ b/packages/shared/src/server/otel/OtelIngestionProcessor.ts
@@ -285,12 +285,19 @@ export class OtelIngestionProcessor {
});
// Construct metadata object with the specified structure
+ // Match v3 path: store full scope object (name, version, attributes)
const metadata = {
...(isLangfuseSDKSpans
? {}
: { attributes: filteredAttributes }),
resourceAttributes: resourceAttributes,
- scopeAttributes: scopeAttributes,
+ scope: {
+ ...(scopeSpan.scope || {}),
+ attributes: scopeAttributes,
+ },
+ // Note: top-level user metadata can overwrite `scope` here.
+ // This preserves the v3 behavior/shape, even though it means
+ // the instrumentation scope object is not guaranteed to win.
...spanMetadata,
...traceMetadata,
};
diff --git a/worker/src/queues/__tests__/otelMetadataProcessing.test.ts b/worker/src/queues/__tests__/otelMetadataProcessing.test.ts
index 7bd2703f48..fa95249cce 100644
--- a/worker/src/queues/__tests__/otelMetadataProcessing.test.ts
+++ b/worker/src/queues/__tests__/otelMetadataProcessing.test.ts
@@ -155,11 +155,13 @@ describe("OTel metadata processing", () => {
}),
);
+ console.log("nameToValue:", JSON.stringify(nameToValue));
+
expect(nameToValue["resourceAttributes.service.name"]).toBe("svc-a");
- expect(nameToValue["scopeAttributes.public_key"]).toBe("pk-test");
+ expect(nameToValue["scope.attributes.public_key"]).toBe("pk-test");
expect(nameToValue["env"]).toBe("prod");
expect(nameToValue["resourceAttributes"]).toBeUndefined();
- expect(nameToValue["scopeAttributes"]).toBeUndefined();
+ expect(nameToValue["scope.attributes"]).toBeUndefined();
});
it("flattens resource/scope attrs to dot-notation (SDK v3.8)", async () => {
@@ -175,10 +177,10 @@ describe("OTel metadata processing", () => {
);
expect(nameToValue["resourceAttributes.service.name"]).toBe("svc-b");
- expect(nameToValue["scopeAttributes.public_key"]).toBe("pk-legacy");
+ expect(nameToValue["scope.attributes.public_key"]).toBe("pk-legacy");
expect(nameToValue["topic"]).toBe("test");
expect(nameToValue["resourceAttributes"]).toBeUndefined();
- expect(nameToValue["scopeAttributes"]).toBeUndefined();
+ expect(nameToValue["scope.attributes"]).toBeUndefined();
});
});
@@ -200,8 +202,12 @@ describe("OTel metadata processing", () => {
expect(meta.resourceAttributes).toBe(
JSON.stringify({ "service.name": "svc-a" }),
);
- expect(meta.scopeAttributes).toBe(
- JSON.stringify({ public_key: "pk-test" }),
+ expect(meta.scope).toBe(
+ JSON.stringify({
+ name: "langfuse-sdk",
+ version: "4.0.0",
+ attributes: { public_key: "pk-test" },
+ }),
);
expect(meta.env).toBe("prod");
});