Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sentry_sdk/integrations/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
17 changes: 17 additions & 0 deletions tests/integrations/anthropic/test_anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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])

Expand Down