diff --git a/sentry_sdk/integrations/anthropic.py b/sentry_sdk/integrations/anthropic.py index 553e703b62..208a4706f5 100644 --- a/sentry_sdk/integrations/anthropic.py +++ b/sentry_sdk/integrations/anthropic.py @@ -124,6 +124,7 @@ def _set_input_data(span, kwargs, integration): """ Set input data for the span based on the provided keyword arguments for the anthropic message creation. """ + set_data_normalized(span, SPANDATA.GEN_AI_OPERATION_NAME, "chat") system_prompt = kwargs.get("system") messages = kwargs.get("messages") if ( diff --git a/tests/integrations/anthropic/test_anthropic.py b/tests/integrations/anthropic/test_anthropic.py index c1d449f892..2204505d47 100644 --- a/tests/integrations/anthropic/test_anthropic.py +++ b/tests/integrations/anthropic/test_anthropic.py @@ -118,6 +118,7 @@ def test_nonstreaming_create_message( assert span["op"] == OP.GEN_AI_CHAT assert span["description"] == "chat model" + assert span["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" assert span["data"][SPANDATA.GEN_AI_REQUEST_MODEL] == "model" if send_default_pii and include_prompts: @@ -187,6 +188,7 @@ async def test_nonstreaming_create_message_async( assert span["op"] == OP.GEN_AI_CHAT assert span["description"] == "chat model" + assert span["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" assert span["data"][SPANDATA.GEN_AI_REQUEST_MODEL] == "model" if send_default_pii and include_prompts: @@ -287,6 +289,7 @@ def test_streaming_create_message( assert span["op"] == OP.GEN_AI_CHAT assert span["description"] == "chat model" + assert span["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" assert span["data"][SPANDATA.GEN_AI_REQUEST_MODEL] == "model" if send_default_pii and include_prompts: @@ -391,6 +394,7 @@ async def test_streaming_create_message_async( assert span["op"] == OP.GEN_AI_CHAT assert span["description"] == "chat model" + assert span["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" assert span["data"][SPANDATA.GEN_AI_REQUEST_MODEL] == "model" if send_default_pii and include_prompts: @@ -522,6 +526,7 @@ def test_streaming_create_message_with_input_json_delta( assert span["op"] == OP.GEN_AI_CHAT assert span["description"] == "chat model" + assert span["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" assert span["data"][SPANDATA.GEN_AI_REQUEST_MODEL] == "model" if send_default_pii and include_prompts: @@ -662,6 +667,7 @@ async def test_streaming_create_message_with_input_json_delta_async( assert span["op"] == OP.GEN_AI_CHAT assert span["description"] == "chat model" + assert span["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" assert span["data"][SPANDATA.GEN_AI_REQUEST_MODEL] == "model" if send_default_pii and include_prompts: @@ -725,6 +731,7 @@ def test_span_status_error(sentry_init, capture_events): assert transaction["spans"][0]["status"] == "internal_error" assert transaction["spans"][0]["tags"]["status"] == "internal_error" assert transaction["contexts"]["trace"]["status"] == "internal_error" + assert transaction["spans"][0]["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" @pytest.mark.asyncio @@ -749,6 +756,7 @@ async def test_span_status_error_async(sentry_init, capture_events): assert transaction["spans"][0]["status"] == "internal_error" assert transaction["spans"][0]["tags"]["status"] == "internal_error" assert transaction["contexts"]["trace"]["status"] == "internal_error" + assert transaction["spans"][0]["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" @pytest.mark.asyncio @@ -796,6 +804,7 @@ def test_span_origin(sentry_init, capture_events): assert event["contexts"]["trace"]["origin"] == "manual" assert event["spans"][0]["origin"] == "auto.ai.anthropic" + assert event["spans"][0]["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" @pytest.mark.asyncio @@ -823,6 +832,7 @@ async def test_span_origin_async(sentry_init, capture_events): assert event["contexts"]["trace"]["origin"] == "manual" assert event["spans"][0]["origin"] == "auto.ai.anthropic" + assert event["spans"][0]["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" @pytest.mark.skipif( @@ -926,6 +936,7 @@ def mock_messages_create(*args, **kwargs): # Verify that the span was created correctly assert span["op"] == "gen_ai.chat" + assert span["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" assert SPANDATA.GEN_AI_REQUEST_MESSAGES in span["data"] # Parse the stored messages @@ -985,6 +996,7 @@ def test_anthropic_message_truncation(sentry_init, capture_events): assert len(chat_spans) > 0 chat_span = chat_spans[0] + assert chat_span["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" assert SPANDATA.GEN_AI_REQUEST_MESSAGES in chat_span["data"] messages_data = chat_span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES] @@ -1052,6 +1064,7 @@ def test_nonstreaming_create_message_with_system_prompt( assert span["op"] == OP.GEN_AI_CHAT assert span["description"] == "chat model" + assert span["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" assert span["data"][SPANDATA.GEN_AI_REQUEST_MODEL] == "model" if send_default_pii and include_prompts: @@ -1130,6 +1143,7 @@ async def test_nonstreaming_create_message_with_system_prompt_async( assert span["op"] == OP.GEN_AI_CHAT assert span["description"] == "chat model" + assert span["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" assert span["data"][SPANDATA.GEN_AI_REQUEST_MODEL] == "model" if send_default_pii and include_prompts: @@ -1240,6 +1254,7 @@ def test_streaming_create_message_with_system_prompt( assert span["op"] == OP.GEN_AI_CHAT assert span["description"] == "chat model" + assert span["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" assert span["data"][SPANDATA.GEN_AI_REQUEST_MODEL] == "model" if send_default_pii and include_prompts: @@ -1354,6 +1369,7 @@ async def test_streaming_create_message_with_system_prompt_async( assert span["op"] == OP.GEN_AI_CHAT assert span["description"] == "chat model" + assert span["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" assert span["data"][SPANDATA.GEN_AI_REQUEST_MODEL] == "model" if send_default_pii and include_prompts: @@ -1414,6 +1430,7 @@ def test_system_prompt_with_complex_structure(sentry_init, capture_events): assert len(event["spans"]) == 1 (span,) = event["spans"] + assert span["data"][SPANDATA.GEN_AI_OPERATION_NAME] == "chat" assert SPANDATA.GEN_AI_REQUEST_MESSAGES in span["data"] stored_messages = json.loads(span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES])