Skip to content

Commit 4dad290

Browse files
committed
Merge branch 'master' into potel-base
2 parents d65c3f7 + 38b570a commit 4dad290

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ for your feedback. How was the migration? Is everything working as expected? Is
3232
default 1024 characters/bytes).
3333

3434
If you want to adjust the limit, you can set a
35-
[`max_value_limit`](https://docs.sentry.io/platforms/python/configuration/options/#max_value_length)
35+
[`max_value_length`](https://docs.sentry.io/platforms/python/configuration/options/#max_value_length)
3636
in your `sentry_sdk.init()`.
3737

3838
- `OpenAI` integration update (#4612) by @antonpirker

sentry_sdk/ai/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ def _normalize_data(data: Any) -> Any:
2323
return list(_normalize_data(x) for x in data)
2424
if isinstance(data, dict):
2525
return {k: _normalize_data(v) for (k, v) in data.items()}
26+
2627
return data
2728

2829

2930
def set_data_normalized(span: Span, key: str, value: Any) -> None:
3031
normalized = _normalize_data(value)
31-
span.set_attribute(key, normalized)
32+
if isinstance(normalized, (int, float, bool, str)):
33+
span.set_attribute(key, normalized)
34+
else:
35+
span.set_attribute(key, str(normalized))

tests/integrations/cohere/test_cohere.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,14 @@ def test_nonstreaming_chat(
5757
assert span["data"][SPANDATA.AI_MODEL_ID] == "some-model"
5858

5959
if send_default_pii and include_prompts:
60-
input_messages = json.loads(span["data"][SPANDATA.AI_INPUT_MESSAGES])
61-
assert "some context" in input_messages[0]["content"]
62-
assert "hello" in input_messages[1]["content"]
60+
assert (
61+
"{'role': 'system', 'content': 'some context'}"
62+
in span["data"][SPANDATA.AI_INPUT_MESSAGES]
63+
)
64+
assert (
65+
"{'role': 'user', 'content': 'hello'}"
66+
in span["data"][SPANDATA.AI_INPUT_MESSAGES]
67+
)
6368
assert "the model response" in span["data"][SPANDATA.AI_RESPONSES]
6469
else:
6570
assert SPANDATA.AI_INPUT_MESSAGES not in span["data"]
@@ -129,9 +134,14 @@ def test_streaming_chat(sentry_init, capture_events, send_default_pii, include_p
129134
assert span["data"][SPANDATA.AI_MODEL_ID] == "some-model"
130135

131136
if send_default_pii and include_prompts:
132-
input_messages = json.loads(span["data"][SPANDATA.AI_INPUT_MESSAGES])
133-
assert "some context" in input_messages[0]["content"]
134-
assert "hello" in input_messages[1]["content"]
137+
assert (
138+
"{'role': 'system', 'content': 'some context'}"
139+
in span["data"][SPANDATA.AI_INPUT_MESSAGES]
140+
)
141+
assert (
142+
"{'role': 'user', 'content': 'hello'}"
143+
in span["data"][SPANDATA.AI_INPUT_MESSAGES]
144+
)
135145
assert "the model response" in span["data"][SPANDATA.AI_RESPONSES]
136146
else:
137147
assert SPANDATA.AI_INPUT_MESSAGES not in span["data"]

tests/integrations/openai/test_openai.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
import pytest
32
from openai import AsyncOpenAI, OpenAI, AsyncStream, Stream, OpenAIError
43
from openai.types import CompletionUsage, CreateEmbeddingResponse, Embedding
@@ -144,11 +143,8 @@ def test_nonstreaming_chat_completion(
144143
assert span["op"] == "gen_ai.chat"
145144

146145
if send_default_pii and include_prompts:
147-
assert "hello" in span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES]["content"]
148-
assert (
149-
"the model response"
150-
in json.loads(span["data"][SPANDATA.GEN_AI_RESPONSE_TEXT])[0]["content"]
151-
)
146+
assert "hello" in span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES]
147+
assert "the model response" in span["data"][SPANDATA.GEN_AI_RESPONSE_TEXT]
152148
else:
153149
assert SPANDATA.GEN_AI_REQUEST_MESSAGES not in span["data"]
154150
assert SPANDATA.GEN_AI_RESPONSE_TEXT not in span["data"]
@@ -189,11 +185,8 @@ async def test_nonstreaming_chat_completion_async(
189185
assert span["op"] == "gen_ai.chat"
190186

191187
if send_default_pii and include_prompts:
192-
assert "hello" in span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES]["content"]
193-
assert (
194-
"the model response"
195-
in json.loads(span["data"][SPANDATA.GEN_AI_RESPONSE_TEXT])[0]["content"]
196-
)
188+
assert "hello" in span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES]
189+
assert "the model response" in span["data"][SPANDATA.GEN_AI_RESPONSE_TEXT]
197190
else:
198191
assert SPANDATA.GEN_AI_REQUEST_MESSAGES not in span["data"]
199192
assert SPANDATA.GEN_AI_RESPONSE_TEXT not in span["data"]
@@ -285,7 +278,7 @@ def test_streaming_chat_completion(
285278
assert span["op"] == "gen_ai.chat"
286279

287280
if send_default_pii and include_prompts:
288-
assert "hello" in span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES]["content"]
281+
assert "hello" in span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES]
289282
assert "hello world" in span["data"][SPANDATA.GEN_AI_RESPONSE_TEXT]
290283
else:
291284
assert SPANDATA.GEN_AI_REQUEST_MESSAGES not in span["data"]
@@ -381,7 +374,7 @@ async def test_streaming_chat_completion_async(
381374
assert span["op"] == "gen_ai.chat"
382375

383376
if send_default_pii and include_prompts:
384-
assert "hello" in span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES]["content"]
377+
assert "hello" in span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES]
385378
assert "hello world" in span["data"][SPANDATA.GEN_AI_RESPONSE_TEXT]
386379
else:
387380
assert SPANDATA.GEN_AI_REQUEST_MESSAGES not in span["data"]

0 commit comments

Comments
 (0)