🪢 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: extract logfire.msg as span and trace name (#5977)
Steffen Schmitz9042b005b8b1
diff --git a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts b/web/src/__tests__/server/api/otel/otelMapping.servertest.tsindex 307ebbc2d2..857bc81b78 100644--- a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts+++ b/web/src/__tests__/server/api/otel/otelMapping.servertest.ts@@ -389,6 +389,34 @@ describe("OTel Resource Span Mapping", () => {).toBe(true);});+ it("should use logfire.msg as span name", async () => {+ const resourceSpan = {+ scopeSpans: [+ {+ spans: [+ {+ ...defaultSpanProps,+ name: "wrong name",+ attributes: [+ {+ key: "logfire.msg",+ value: { stringValue: "right name" },+ },+ ],+ },+ ],+ },+ ],+ };++ // When+ const langfuseEvents = convertOtelSpanToIngestionEvent(resourceSpan);++ // Then+ expect(langfuseEvents[0].body.name).toBe("right name");+ expect(langfuseEvents[1].body.name).toBe("right name");+ });+it.each([["should cast input_tokens from string to number",diff --git a/web/src/features/otel/server/index.ts b/web/src/features/otel/server/index.tsindex 3bcc180dfa..d4e39963a4 100644--- a/web/src/features/otel/server/index.ts+++ b/web/src/features/otel/server/index.ts@@ -248,6 +248,21 @@ const extractEnvironment = (return "default";};+const extractName = (+ spanName: string,+ attributes: Record<string, unknown>,+): string => {+ const nameKeys = ["logfire.msg"];+ for (const key of nameKeys) {+ if (attributes[key]) {+ return typeof attributes[key] === "string"+ ? (attributes[key] as string)+ : JSON.stringify(attributes[key]);+ }+ }+ return spanName;+};+const extractUserId = (attributes: Record<string, unknown>,): string | undefined => {@@ -391,7 +406,7 @@ export const convertOtelSpanToIngestionEvent = (const trace = {id: Buffer.from(span.traceId?.data ?? span.traceId).toString("hex"),timestamp: convertNanoTimestampToISO(span.startTimeUnixNano),- name: span.name,+ name: extractName(span.name, attributes),metadata: {attributes,resourceAttributes,@@ -429,7 +444,7 @@ export const convertOtelSpanToIngestionEvent = ("hex",),parentObservationId,- name: span.name,+ name: extractName(span.name, attributes),startTime: convertNanoTimestampToISO(span.startTimeUnixNano),endTime: convertNanoTimestampToISO(span.endTimeUnixNano),