From 0808182bc6fe961821d2374da2778d2d5e6d8987 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 5 Nov 2024 13:45:14 +0100 Subject: [PATCH 1/2] Fixed cohere tests --- sentry_sdk/ai/utils.py | 4 ++-- tests/integrations/cohere/test_cohere.py | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/sentry_sdk/ai/utils.py b/sentry_sdk/ai/utils.py index ed3494f679..ca2c64385d 100644 --- a/sentry_sdk/ai/utils.py +++ b/sentry_sdk/ai/utils.py @@ -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): @@ -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)) diff --git a/tests/integrations/cohere/test_cohere.py b/tests/integrations/cohere/test_cohere.py index c0dff2214e..20371029d5 100644 --- a/tests/integrations/cohere/test_cohere.py +++ b/tests/integrations/cohere/test_cohere.py @@ -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"] @@ -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"] @@ -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" From 311947036df7716c3d453c87b86833ba041ee62b Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 5 Nov 2024 14:18:18 +0100 Subject: [PATCH 2/2] not needed anymore --- sentry_sdk/ai/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/ai/utils.py b/sentry_sdk/ai/utils.py index ca2c64385d..ed3494f679 100644 --- a/sentry_sdk/ai/utils.py +++ b/sentry_sdk/ai/utils.py @@ -4,7 +4,7 @@ from typing import Any from sentry_sdk.tracing import Span -from sentry_sdk.utils import _serialize_span_attribute, logger +from sentry_sdk.utils import logger def _normalize_data(data): @@ -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, _serialize_span_attribute(normalized)) + span.set_data(key, normalized)