Skip to content

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

fix(otel): use LiteLLM dispatched model for routed calls (#17128)

Hassieb Pakzade42b0195fa1b
diff --git a/packages/shared/src/server/otel/OtelIngestionProcessor.ts b/packages/shared/src/server/otel/OtelIngestionProcessor.ts
index 6f265a3a76..e697dd4cbc 100644
--- a/packages/shared/src/server/otel/OtelIngestionProcessor.ts
+++ b/packages/shared/src/server/otel/OtelIngestionProcessor.ts
@@ -3020,6 +3020,7 @@ export class OtelIngestionProcessor {
): string | undefined {
const modelNameKeys = [
LangfuseOtelSpanAttributes.OBSERVATION_MODEL,
+ "litellm.provider.model",
"gen_ai.response.model",
"ai.model.id",
"gen_ai.request.model",
diff --git a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts b/web/src/__tests__/server/api/otel/otelMapping.servertest.ts
index c47629ad33..06bbf1562f 100644
--- a/web/src/__tests__/server/api/otel/otelMapping.servertest.ts
+++ b/web/src/__tests__/server/api/otel/otelMapping.servertest.ts
@@ -3297,6 +3297,49 @@ describe("OTel Resource Span Mapping", () => {
expect(langfuseEvents[1].body.name).toBe("right name");
});
+ it("should prefer LiteLLM's dispatched provider model over the router alias", async () => {
+ const resourceSpan = {
+ scopeSpans: [
+ {
+ scope: { name: "litellm" },
+ spans: [
+ {
+ ...defaultSpanProps,
+ attributes: [
+ {
+ key: "gen_ai.operation.name",
+ value: { stringValue: "chat" },
+ },
+ {
+ key: "gen_ai.request.model",
+ value: { stringValue: "router" },
+ },
+ {
+ key: "gen_ai.response.model",
+ value: { stringValue: "router" },
+ },
+ {
+ key: "litellm.provider.model",
+ value: { stringValue: "openai/gpt-4o-mini" },
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ };
+
+ const langfuseEvents = await convertOtelSpanToIngestionEvent(
+ resourceSpan,
+ new Set(),
+ );
+ const observationEvent = langfuseEvents.find(
+ (event) => event.type !== "trace-create",
+ );
+
+ expect(observationEvent?.body.model).toBe("openai/gpt-4o-mini");
+ });
+
it.each([
[
"should cast input_tokens from string to number",