Skip to content

fix(litellm): Set operation name from call type instead of chat fallback#6792

Open
VihaanAgarwal wants to merge 1 commit into
getsentry:masterfrom
VihaanAgarwal:fix/litellm-operation-name
Open

fix(litellm): Set operation name from call type instead of chat fallback#6792
VihaanAgarwal wants to merge 1 commit into
getsentry:masterfrom
VihaanAgarwal:fix/litellm-operation-name

Conversation

@VihaanAgarwal

Copy link
Copy Markdown

Fixes #6442.

The input callback mapped every call type except embedding/aembedding to chat, so a litellm.image_generation() call showed up in Sentry as chat dall-e-3 with gen_ai.operation.name: chat. Same story for text completions, speech, transcription, rerank and the rest.

This replaces the binary fallback with an explicit table of the call types we can name accurately:

  • completion/acompletion -> chat
  • text_completion/atext_completion -> text_completion
  • embedding/aembedding -> embeddings
  • responses/aresponses -> responses

Each maps to its matching OP.GEN_AI_* span op (the constants for text_completion and responses already exist and are used by the langchain and openai integrations).

For everything else, gen_ai.operation.name is simply not set. Recording a guess is what this issue is about, and litellm has 140+ call types (batch, files, assistants, video...), most of which have no semconv equivalent. The raw call type still ends up in the span name (image_generation dall-e-3), so the spans stay identifiable. I kept gen_ai.chat as the span op fallback for unmapped types so those spans keep flowing into the AI views like before; happy to change that if you'd rather they drop out.

One test tweak: test_response_without_usage built callback kwargs without a call_type and asserted the span was named chat ..., which only held because of the fallback. Real callbacks always carry call_type (litellm's Logging.pre_call sets it), so I added "call_type": "completion" to those kwargs rather than special casing a missing key as chat.

Tests cover all eight mapped call types plus the unknown case. The litellm test module passes locally except test_multiple_providers, which errors at setup on current master too (missing optional provider package in my env).

@VihaanAgarwal VihaanAgarwal requested a review from a team as a code owner July 9, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Only set accurate operation name in litellm

1 participant