From 05589e82da988b30d9dc4e99d81d5cabf5fd5c9d Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Mon, 13 Oct 2025 10:53:11 +0200 Subject: [PATCH 1/3] fix(litellm): Classify embeddings correctly --- sentry_sdk/integrations/litellm.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/integrations/litellm.py b/sentry_sdk/integrations/litellm.py index 2582c2bc05..41d939f281 100644 --- a/sentry_sdk/integrations/litellm.py +++ b/sentry_sdk/integrations/litellm.py @@ -18,6 +18,11 @@ except ImportError: raise DidNotEnable("LiteLLM not installed") +_CALL_TYPE_TO_OPERATION = { + "embedding": "embeddings", + "completion": "chat", +} + def _get_metadata_dict(kwargs): # type: (Dict[str, Any]) -> Dict[str, Any] @@ -48,8 +53,11 @@ def _input_callback(kwargs): model = full_model provider = "unknown" - messages = kwargs.get("messages", []) - operation = "chat" if messages else "embeddings" + call_type = kwargs.get("call_type", None) + if call_type not in _CALL_TYPE_TO_OPERATION: + return + + operation = _CALL_TYPE_TO_OPERATION[call_type] # Start a new span/transaction span = get_start_span_function()( @@ -71,6 +79,7 @@ def _input_callback(kwargs): set_data_normalized(span, SPANDATA.GEN_AI_OPERATION_NAME, operation) # Record messages if allowed + messages = kwargs.get("messages", []) if messages and should_send_default_pii() and integration.include_prompts: set_data_normalized( span, SPANDATA.GEN_AI_REQUEST_MESSAGES, messages, unpack=False From f407e6b99c7674fd7a8a970ac2daebded50f9005 Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Mon, 13 Oct 2025 11:44:17 +0200 Subject: [PATCH 2/3] fix tests --- sentry_sdk/integrations/litellm.py | 13 ++++--------- tests/integrations/litellm/test_litellm.py | 5 +++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/sentry_sdk/integrations/litellm.py b/sentry_sdk/integrations/litellm.py index 41d939f281..1f047b1c1d 100644 --- a/sentry_sdk/integrations/litellm.py +++ b/sentry_sdk/integrations/litellm.py @@ -18,11 +18,6 @@ except ImportError: raise DidNotEnable("LiteLLM not installed") -_CALL_TYPE_TO_OPERATION = { - "embedding": "embeddings", - "completion": "chat", -} - def _get_metadata_dict(kwargs): # type: (Dict[str, Any]) -> Dict[str, Any] @@ -54,10 +49,10 @@ def _input_callback(kwargs): provider = "unknown" call_type = kwargs.get("call_type", None) - if call_type not in _CALL_TYPE_TO_OPERATION: - return - - operation = _CALL_TYPE_TO_OPERATION[call_type] + if call_type == "embedding": + operation = "embeddings" + else: + operation = "chat" # Start a new span/transaction span = get_start_span_function()( diff --git a/tests/integrations/litellm/test_litellm.py b/tests/integrations/litellm/test_litellm.py index b600c32905..f4f3d4aa6c 100644 --- a/tests/integrations/litellm/test_litellm.py +++ b/tests/integrations/litellm/test_litellm.py @@ -208,14 +208,15 @@ def test_embeddings_create(sentry_init, capture_events): ) events = capture_events() + messages = [{"role": "user", "content": "Some text to test embeddings"}] mock_response = MockEmbeddingResponse() with start_transaction(name="litellm test"): - # For embeddings, messages would be empty kwargs = { "model": "text-embedding-ada-002", "input": "Hello!", - "messages": [], # Empty for embeddings + "messages": messages, + "call_type": "embeddings", } _input_callback(kwargs) From 8aef4188447f47f29c04e1898babd7a85be4d5d8 Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Mon, 13 Oct 2025 12:51:21 +0200 Subject: [PATCH 3/3] string fix --- tests/integrations/litellm/test_litellm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integrations/litellm/test_litellm.py b/tests/integrations/litellm/test_litellm.py index f4f3d4aa6c..19ae206c85 100644 --- a/tests/integrations/litellm/test_litellm.py +++ b/tests/integrations/litellm/test_litellm.py @@ -216,7 +216,7 @@ def test_embeddings_create(sentry_init, capture_events): "model": "text-embedding-ada-002", "input": "Hello!", "messages": messages, - "call_type": "embeddings", + "call_type": "embedding", } _input_callback(kwargs)