Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions sentry_sdk/ai/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Any

from sentry_sdk.tracing import Span
from sentry_sdk.utils import logger
from sentry_sdk.utils import _serialize_span_attribute, logger


def _normalize_data(data):
Expand All @@ -29,4 +29,4 @@ def _normalize_data(data):
def set_data_normalized(span, key, value):
# type: (Span, str, Any) -> None
normalized = _normalize_data(value)
span.set_data(key, normalized)
span.set_data(key, _serialize_span_attribute(normalized))
12 changes: 7 additions & 5 deletions tests/integrations/cohere/test_cohere.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ def test_nonstreaming_chat(
assert span["data"]["ai.model_id"] == "some-model"

if send_default_pii and include_prompts:
assert "some context" in span["data"]["ai.input_messages"][0]["content"]
assert "hello" in span["data"]["ai.input_messages"][1]["content"]
input_messages = json.loads(span["data"]["ai.input_messages"])
assert "some context" in input_messages[0]["content"]
assert "hello" in input_messages[1]["content"]
assert "the model response" in span["data"]["ai.responses"]
else:
assert "ai.input_messages" not in span["data"]
Expand Down Expand Up @@ -127,8 +128,9 @@ def test_streaming_chat(sentry_init, capture_events, send_default_pii, include_p
assert span["data"]["ai.model_id"] == "some-model"

if send_default_pii and include_prompts:
assert "some context" in span["data"]["ai.input_messages"][0]["content"]
assert "hello" in span["data"]["ai.input_messages"][1]["content"]
input_messages = json.loads(span["data"]["ai.input_messages"])
assert "some context" in input_messages[0]["content"]
assert "hello" in input_messages[1]["content"]
assert "the model response" in span["data"]["ai.responses"]
else:
assert "ai.input_messages" not in span["data"]
Expand All @@ -150,7 +152,7 @@ def test_bad_chat(sentry_init, capture_events):
with pytest.raises(httpx.HTTPError):
client.chat(model="some-model", message="hello")

(event,) = events
(event, _) = events
assert event["level"] == "error"


Expand Down
Loading