Skip to content

Commit 7773a27

Browse files
merge
2 parents b618cc8 + dde7bf4 commit 7773a27

9 files changed

Lines changed: 453 additions & 420 deletions

File tree

sentry_sdk/client.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,6 @@ def _serialized_v1_attribute_to_serialized_v2_attribute(
149149
"type": "string",
150150
}
151151

152-
if attribute_value is None:
153-
return {
154-
"value": "None",
155-
"type": "string",
156-
}
157-
158152
return None
159153

160154

tests/integrations/google_genai/test_google_genai.py

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@ def get_weather(location: str) -> str:
427427
tools_data_str = invoke_span["attributes"][
428428
SPANDATA.GEN_AI_REQUEST_AVAILABLE_TOOLS
429429
]
430-
431430
# Parse the JSON string to verify content
432431
tools_data = json.loads(tools_data_str)
433432
assert len(tools_data) == 2
@@ -452,7 +451,6 @@ def get_weather(location: str) -> str:
452451

453452
# Check that tools are recorded (data is serialized as a string)
454453
tools_data_str = invoke_span["data"][SPANDATA.GEN_AI_REQUEST_AVAILABLE_TOOLS]
455-
456454
# Parse the JSON string to verify content
457455
tools_data = json.loads(tools_data_str)
458456
assert len(tools_data) == 2
@@ -701,14 +699,10 @@ def test_streaming_generate_content(
701699
# Verify accumulated response text (all chunks combined)
702700
expected_full_text = "Hello! How can I help you today?"
703701
# Response text is stored as a JSON string
704-
if stream_gen_ai_spans:
705-
chat_response_text = json.loads(
706-
chat_span["attributes"][SPANDATA.GEN_AI_RESPONSE_TEXT]
707-
)
708-
else:
709-
chat_response_text = json.loads(
710-
chat_span["data"][SPANDATA.GEN_AI_RESPONSE_TEXT]
711-
)
702+
chat_response_text = json.loads(
703+
chat_span["attributes"][SPANDATA.GEN_AI_RESPONSE_TEXT]
704+
)
705+
712706
assert chat_response_text == [expected_full_text]
713707

714708
# Verify finish reasons (only the final chunk has a finish reason)
@@ -762,14 +756,9 @@ def test_streaming_generate_content(
762756
# Verify accumulated response text (all chunks combined)
763757
expected_full_text = "Hello! How can I help you today?"
764758
# Response text is stored as a JSON string
765-
if stream_gen_ai_spans:
766-
chat_response_text = json.loads(
767-
chat_span["attributes"][SPANDATA.GEN_AI_RESPONSE_TEXT]
768-
)
769-
else:
770-
chat_response_text = json.loads(
771-
chat_span["data"][SPANDATA.GEN_AI_RESPONSE_TEXT]
772-
)
759+
chat_response_text = json.loads(
760+
chat_span["data"][SPANDATA.GEN_AI_RESPONSE_TEXT]
761+
)
773762
assert chat_response_text == [expected_full_text]
774763

775764
# Verify finish reasons (only the final chunk has a finish reason)
@@ -1569,7 +1558,6 @@ def test_embed_content(
15691558
(event,) = events
15701559

15711560
assert event["type"] == "transaction"
1572-
15731561
assert event["transaction"] == "google_genai_embeddings"
15741562

15751563
# Should have 1 span for embeddings
@@ -1674,7 +1662,6 @@ def test_embed_content_string_input(
16741662

16751663
# Check that single string is handled correctly
16761664
input_texts = json.loads(embed_span["data"][SPANDATA.GEN_AI_EMBEDDINGS_INPUT])
1677-
16781665
assert input_texts == ["Single text input"]
16791666
# Should use token_count from statistics (5), not billable_character_count (10)
16801667
# Note: Only available in newer versions with ContentEmbeddingStatistics
@@ -2041,7 +2028,6 @@ async def test_async_embed_content_string_input(
20412028
input_texts = json.loads(
20422029
embed_span["attributes"][SPANDATA.GEN_AI_EMBEDDINGS_INPUT]
20432030
)
2044-
20452031
assert input_texts == ["Single text input"]
20462032
# Should use token_count from statistics (5), not billable_character_count (10)
20472033
# Note: Only available in newer versions with ContentEmbeddingStatistics
@@ -2065,7 +2051,6 @@ async def test_async_embed_content_string_input(
20652051

20662052
# Check that single string is handled correctly
20672053
input_texts = json.loads(embed_span["data"][SPANDATA.GEN_AI_EMBEDDINGS_INPUT])
2068-
20692054
assert input_texts == ["Single text input"]
20702055
# Should use token_count from statistics (5), not billable_character_count (10)
20712056
# Note: Only available in newer versions with ContentEmbeddingStatistics

tests/integrations/huggingface_hub/test_huggingface_hub.py

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
if TYPE_CHECKING:
20-
pass
20+
from typing import Any
2121

2222

2323
HF_VERSION = package_version("huggingface-hub")
@@ -471,14 +471,14 @@ def mock_hf_chat_completion_api_streaming_tools(httpx_mock):
471471
@pytest.mark.parametrize("send_default_pii", [True, False])
472472
@pytest.mark.parametrize("include_prompts", [True, False])
473473
def test_text_generation(
474-
sentry_init,
475-
capture_events,
476-
capture_items,
477-
send_default_pii,
478-
include_prompts,
479-
mock_hf_text_generation_api,
480-
stream_gen_ai_spans,
481-
):
474+
sentry_init: "Any",
475+
capture_events: "Any",
476+
capture_items: "Any",
477+
send_default_pii: "Any",
478+
include_prompts: "Any",
479+
mock_hf_text_generation_api: "Any",
480+
stream_gen_ai_spans: "Any",
481+
) -> None:
482482
sentry_init(
483483
traces_sample_rate=1.0,
484484
send_default_pii=send_default_pii,
@@ -606,14 +606,14 @@ def test_text_generation(
606606
@pytest.mark.parametrize("send_default_pii", [True, False])
607607
@pytest.mark.parametrize("include_prompts", [True, False])
608608
def test_text_generation_streaming(
609-
sentry_init,
610-
capture_events,
611-
capture_items,
612-
send_default_pii,
613-
include_prompts,
614-
mock_hf_text_generation_api_streaming,
615-
stream_gen_ai_spans,
616-
):
609+
sentry_init: "Any",
610+
capture_events: "Any",
611+
capture_items: "Any",
612+
send_default_pii: "Any",
613+
include_prompts: "Any",
614+
mock_hf_text_generation_api_streaming: "Any",
615+
stream_gen_ai_spans: "Any",
616+
) -> None:
617617
sentry_init(
618618
traces_sample_rate=1.0,
619619
send_default_pii=send_default_pii,
@@ -739,14 +739,14 @@ def test_text_generation_streaming(
739739
@pytest.mark.parametrize("send_default_pii", [True, False])
740740
@pytest.mark.parametrize("include_prompts", [True, False])
741741
def test_chat_completion(
742-
sentry_init,
743-
capture_events,
744-
capture_items,
745-
send_default_pii,
746-
include_prompts,
747-
mock_hf_chat_completion_api,
748-
stream_gen_ai_spans,
749-
):
742+
sentry_init: "Any",
743+
capture_events: "Any",
744+
capture_items: "Any",
745+
send_default_pii: "Any",
746+
include_prompts: "Any",
747+
mock_hf_chat_completion_api: "Any",
748+
stream_gen_ai_spans: "Any",
749+
) -> None:
750750
sentry_init(
751751
traces_sample_rate=1.0,
752752
send_default_pii=send_default_pii,
@@ -876,14 +876,14 @@ def test_chat_completion(
876876
@pytest.mark.parametrize("send_default_pii", [True, False])
877877
@pytest.mark.parametrize("include_prompts", [True, False])
878878
def test_chat_completion_streaming(
879-
sentry_init,
880-
capture_events,
881-
capture_items,
882-
send_default_pii,
883-
include_prompts,
884-
mock_hf_chat_completion_api_streaming,
885-
stream_gen_ai_spans,
886-
):
879+
sentry_init: "Any",
880+
capture_events: "Any",
881+
capture_items: "Any",
882+
send_default_pii: "Any",
883+
include_prompts: "Any",
884+
mock_hf_chat_completion_api_streaming: "Any",
885+
stream_gen_ai_spans: "Any",
886+
) -> None:
887887
sentry_init(
888888
traces_sample_rate=1.0,
889889
send_default_pii=send_default_pii,
@@ -938,7 +938,6 @@ def test_chat_completion_streaming(
938938
"thread.id": mock.ANY,
939939
"thread.name": mock.ANY,
940940
}
941-
942941
# usage is not available in older versions of the library
943942
if HF_VERSION and HF_VERSION >= (0, 26, 0):
944943
expected_data["gen_ai.usage.input_tokens"] = 183
@@ -1016,12 +1015,12 @@ def test_chat_completion_streaming(
10161015
@pytest.mark.parametrize("stream_gen_ai_spans", [True, False])
10171016
@pytest.mark.httpx_mock(assert_all_requests_were_expected=False)
10181017
def test_chat_completion_api_error(
1019-
sentry_init,
1020-
capture_events,
1021-
capture_items,
1022-
mock_hf_api_with_errors,
1023-
stream_gen_ai_spans,
1024-
):
1018+
sentry_init: "Any",
1019+
capture_events: "Any",
1020+
capture_items: "Any",
1021+
mock_hf_api_with_errors: "Any",
1022+
stream_gen_ai_spans: "Any",
1023+
) -> None:
10251024
sentry_init(
10261025
traces_sample_rate=1.0,
10271026
stream_gen_ai_spans=stream_gen_ai_spans,
@@ -1130,12 +1129,12 @@ def test_chat_completion_api_error(
11301129
@pytest.mark.parametrize("stream_gen_ai_spans", [True, False])
11311130
@pytest.mark.httpx_mock(assert_all_requests_were_expected=False)
11321131
def test_span_status_error(
1133-
sentry_init,
1134-
capture_events,
1135-
capture_items,
1136-
mock_hf_api_with_errors,
1137-
stream_gen_ai_spans,
1138-
):
1132+
sentry_init: "Any",
1133+
capture_events: "Any",
1134+
capture_items: "Any",
1135+
mock_hf_api_with_errors: "Any",
1136+
stream_gen_ai_spans: "Any",
1137+
) -> None:
11391138
client = get_hf_provider_inference_client()
11401139

11411140
sentry_init(
@@ -1198,13 +1197,13 @@ def test_span_status_error(
11981197
@pytest.mark.parametrize("send_default_pii", [True, False])
11991198
@pytest.mark.parametrize("include_prompts", [True, False])
12001199
def test_chat_completion_with_tools(
1201-
sentry_init,
1202-
capture_events,
1203-
capture_items,
1204-
send_default_pii,
1205-
include_prompts,
1206-
mock_hf_chat_completion_api_tools,
1207-
stream_gen_ai_spans,
1200+
sentry_init: "Any",
1201+
capture_events: "Any",
1202+
capture_items: "Any",
1203+
send_default_pii: "Any",
1204+
include_prompts: "Any",
1205+
mock_hf_chat_completion_api_tools: "Any",
1206+
stream_gen_ai_spans: "Any",
12081207
):
12091208
sentry_init(
12101209
traces_sample_rate=1.0,
@@ -1354,14 +1353,14 @@ def test_chat_completion_with_tools(
13541353
@pytest.mark.parametrize("send_default_pii", [True, False])
13551354
@pytest.mark.parametrize("include_prompts", [True, False])
13561355
def test_chat_completion_streaming_with_tools(
1357-
sentry_init,
1358-
capture_events,
1359-
capture_items,
1360-
send_default_pii,
1361-
include_prompts,
1362-
mock_hf_chat_completion_api_streaming_tools,
1363-
stream_gen_ai_spans,
1364-
):
1356+
sentry_init: "Any",
1357+
capture_events: "Any",
1358+
capture_items: "Any",
1359+
send_default_pii: "Any",
1360+
include_prompts: "Any",
1361+
mock_hf_chat_completion_api_streaming_tools: "Any",
1362+
stream_gen_ai_spans: "Any",
1363+
) -> None:
13651364
sentry_init(
13661365
traces_sample_rate=1.0,
13671366
send_default_pii=send_default_pii,

0 commit comments

Comments
 (0)