Skip to content

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

feat(otel): support mapping of custom trace_id for litellm (#11553)

Jannik Maierhöferf79a5cc52f19
diff --git a/packages/shared/src/server/otel/OtelIngestionProcessor.ts b/packages/shared/src/server/otel/OtelIngestionProcessor.ts
index c5a71b1273..354e109963 100644
--- a/packages/shared/src/server/otel/OtelIngestionProcessor.ts
+++ b/packages/shared/src/server/otel/OtelIngestionProcessor.ts
@@ -194,7 +194,12 @@ export class OtelIngestionProcessor {
const scopeAttributes = this.extractScopeAttributes(scopeSpan);
for (const span of scopeSpan?.spans ?? []) {
const spanAttributes = this.extractSpanAttributes(span);
- const traceId = this.parseId(span.traceId);
+ // For LiteLLM spans, use langfuse.trace.id from attributes if provided
+ const isLiteLLMSpan = scopeSpan?.scope?.name === "litellm";
+ const traceId =
+ isLiteLLMSpan && spanAttributes["langfuse.trace.id"]
+ ? (spanAttributes["langfuse.trace.id"] as string)
+ : this.parseId(span.traceId);
const spanId = this.parseId(span.spanId);
const parentSpanId = span?.parentSpanId
? this.parseId(span.parentSpanId)
@@ -629,7 +634,12 @@ export class OtelIngestionProcessor {
const events: IngestionEventType[] = [];
const attributes = this.extractSpanAttributes(span);
- const traceId = this.parseId(span.traceId?.data ?? span.traceId);
+ // For LiteLLM spans, use langfuse.trace.id from attributes if provided
+ const isLiteLLMSpan = scopeSpan?.scope?.name === "litellm";
+ const traceId =
+ isLiteLLMSpan && attributes["langfuse.trace.id"]
+ ? (attributes["langfuse.trace.id"] as string)
+ : this.parseId(span.traceId?.data ?? span.traceId);
const parentObservationId = span?.parentSpanId
? this.parseId(span.parentSpanId?.data ?? span.parentSpanId)
: null;