diff --git a/sentry_sdk/integrations/litellm.py b/sentry_sdk/integrations/litellm.py index 2582c2bc05..1f047b1c1d 100644 --- a/sentry_sdk/integrations/litellm.py +++ b/sentry_sdk/integrations/litellm.py @@ -48,8 +48,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 == "embedding": + operation = "embeddings" + else: + operation = "chat" # Start a new span/transaction span = get_start_span_function()( @@ -71,6 +74,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 diff --git a/tests/integrations/litellm/test_litellm.py b/tests/integrations/litellm/test_litellm.py index b600c32905..19ae206c85 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": "embedding", } _input_callback(kwargs)