🪢 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): map foreign observation levels onto the Langfuse enum (#15513)
Steffen Schmitz765688825715
diff --git a/packages/shared/src/server/otel/OtelIngestionProcessor.ts b/packages/shared/src/server/otel/OtelIngestionProcessor.tsindex 1027b4836b..3e39110032 100644--- a/packages/shared/src/server/otel/OtelIngestionProcessor.ts+++ b/packages/shared/src/server/otel/OtelIngestionProcessor.ts@@ -3,6 +3,7 @@ import { randomUUID } from "crypto";import {ForbiddenError,ObservationLevel,+ type ObservationLevelType,ObservationType,ObservationTypeDomain,} from "../../";@@ -32,6 +33,35 @@ import { OtelIngestionQueue } from "../redis/otelIngestionQueue";import { isValidDateString, flattenJsonToPathArrays } from "./utils";import { convertDateToClickhouseDateTime } from "../clickhouse/client";+// Foreign level vocabularies observed from OTel senders (OTel severity+// names, python logging, loguru, console) mapped onto the Langfuse enum.+// The classic ingestion API keeps its strict enum; only the+// OTel adapter translates. Unknown values return undefined so the caller's+// status-derived fallback applies instead of masking it with DEFAULT.+const OBSERVATION_LEVEL_ALIASES: Record<string, ObservationLevelType> = {+ DEBUG: ObservationLevel.DEBUG,+ TRACE: ObservationLevel.DEBUG,+ VERBOSE: ObservationLevel.DEBUG,+ DEFAULT: ObservationLevel.DEFAULT,+ INFO: ObservationLevel.DEFAULT,+ LOG: ObservationLevel.DEFAULT,+ NOTICE: ObservationLevel.DEFAULT,+ OK: ObservationLevel.DEFAULT,+ SUCCESS: ObservationLevel.DEFAULT,+ WARNING: ObservationLevel.WARNING,+ WARN: ObservationLevel.WARNING,+ ERROR: ObservationLevel.ERROR,+ FATAL: ObservationLevel.ERROR,+ CRITICAL: ObservationLevel.ERROR,+};++function parseObservationLevel(+ value: unknown,+): ObservationLevelType | undefined {+ if (typeof value !== "string") return undefined;+ return OBSERVATION_LEVEL_ALIASES[value.trim().toUpperCase()];+}+// Type definitions for internal processor stateinterface TraceState {hasFullTrace: boolean;@@ -459,9 +489,11 @@ export class OtelIngestionProcessor {endTimeISO,level:- spanAttributes[- LangfuseOtelSpanAttributes.OBSERVATION_LEVEL- ] ??+ parseObservationLevel(+ spanAttributes[+ LangfuseOtelSpanAttributes.OBSERVATION_LEVEL+ ],+ ) ??(span.status?.code === 2? ObservationLevel.ERROR: scopeSpan?.scope?.name === "livekit-agents" &&@@ -1094,7 +1126,9 @@ export class OtelIngestionProcessor {),metadata: normalizedToolMetadata.metadata,level:- attributes[LangfuseOtelSpanAttributes.OBSERVATION_LEVEL] ??+ parseObservationLevel(+ attributes[LangfuseOtelSpanAttributes.OBSERVATION_LEVEL],+ ) ??(span.status?.code === 2? ObservationLevel.ERROR: scopeSpan?.scope?.name === "livekit-agents" &&diff --git a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts b/web/src/__tests__/server/api/otel/otelMapping.servertest.tsindex a5266c2688..ae3bd13988 100644--- a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts+++ b/web/src/__tests__/server/api/otel/otelMapping.servertest.ts@@ -3973,6 +3973,55 @@ describe("OTel Resource Span Mapping", () => {).toBe("langfuse-prompt-experiment");});+ it("normalizes foreign observation-level vocabularies at the OTel seam (LFE-14547)", async () => {+ const buildSpan = (level: string, status: Record<string, any> = {}) =>+ ({+ scopeSpans: [+ {+ spans: [+ {+ ...defaultSpanProps,+ attributes: [+ {+ key: "langfuse.observation.level",+ value: { stringValue: level },+ },+ ],+ status,+ },+ ],+ },+ ],+ }) as unknown as ResourceSpan;++ const eventLevel = (level: string, status?: Record<string, any>) =>+ createTestOtelProcessor().processToEvent([buildSpan(level, status)])[0]+ .level;++ // OTel severity names, python logging, and loguru vocabularies map onto+ // the Langfuse enum instead of landing raw in events_full.+ expect(eventLevel("warning")).toBe("WARNING");+ expect(eventLevel("INFO")).toBe("DEFAULT");+ expect(eventLevel("FATAL")).toBe("ERROR");++ // Unknown values defer to the status-derived fallback rather than+ // masking it with DEFAULT.+ expect(eventLevel("[REDACTED]", { code: 2 })).toBe("ERROR");+ expect(eventLevel("[REDACTED]")).toBe("DEFAULT");++ // The legacy observation body gets the same canonical value, so the+ // ingestion-schema enum parse passes and the observation is no longer+ // dropped from the legacy tables.+ const ingestionEvents = await convertOtelSpanToIngestionEvent(+ buildSpan("warning"),+ new Set(),+ );+ const observation = ingestionEvents.find(+ (e) => e.type !== "trace-create",+ );+ expect(observation?.body.level).toBe("WARNING");+ });+describe("prompt linking gated to GENERATION observations", () => {const buildResourceSpan = (attributes: Record<string, any>[]) =>({