Skip to content

Commit 88fc76e

Browse files
cleanup
1 parent 9b20bd2 commit 88fc76e

6 files changed

Lines changed: 31 additions & 58 deletions

File tree

tests/integrations/anthropic/test_anthropic.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3725,7 +3725,7 @@ def test_message_with_base64_pdf(sentry_init, capture_items):
37253725
"source": {
37263726
"type": "base64",
37273727
"media_type": "application/pdf",
3728-
"attributes": "JVBERi0xLjQKJeLj...base64pdfdata",
3728+
"data": "JVBERi0xLjQKJeLj...base64pdfdata",
37293729
},
37303730
},
37313731
],
@@ -3859,7 +3859,7 @@ def test_message_with_mixed_content(sentry_init, capture_items):
38593859
"source": {
38603860
"type": "base64",
38613861
"media_type": "image/png",
3862-
"attributes": "iVBORw0KGgo...base64imagedata",
3862+
"data": "iVBORw0KGgo...base64imagedata",
38633863
},
38643864
},
38653865
{
@@ -3874,7 +3874,7 @@ def test_message_with_mixed_content(sentry_init, capture_items):
38743874
"source": {
38753875
"type": "base64",
38763876
"media_type": "application/pdf",
3877-
"attributes": "JVBERi0xLjQK...base64pdfdata",
3877+
"data": "JVBERi0xLjQK...base64pdfdata",
38783878
},
38793879
},
38803880
{"type": "text", "text": "Please provide a detailed analysis."},
@@ -3941,7 +3941,7 @@ def test_message_with_multiple_images_different_formats(sentry_init, capture_ite
39413941
"source": {
39423942
"type": "base64",
39433943
"media_type": "image/jpeg",
3944-
"attributes": "base64data1...",
3944+
"data": "base64data1...",
39453945
},
39463946
},
39473947
{
@@ -4017,7 +4017,7 @@ def test_binary_content_not_stored_when_pii_disabled(sentry_init, capture_items)
40174017
"source": {
40184018
"type": "base64",
40194019
"media_type": "image/jpeg",
4020-
"attributes": "base64encodeddatahere...",
4020+
"data": "base64encodeddatahere...",
40214021
},
40224022
},
40234023
],
@@ -4056,7 +4056,7 @@ def test_binary_content_not_stored_when_prompts_disabled(sentry_init, capture_it
40564056
"source": {
40574057
"type": "base64",
40584058
"media_type": "image/jpeg",
4059-
"attributes": "base64encodeddatahere...",
4059+
"data": "base64encodeddatahere...",
40604060
},
40614061
},
40624062
],
@@ -4106,7 +4106,7 @@ def test_cache_tokens_nonstreaming(sentry_init, capture_items):
41064106
model="claude-3-5-sonnet-20241022",
41074107
)
41084108

4109-
(span,) = [item.payload for item in items if item.type == "span"]
4109+
(span,) = (item.payload for item in items if item.type == "span")
41104110
# input_tokens normalized: 100 + 80 (cache_read) + 20 (cache_write) = 200
41114111
assert span["attributes"][SPANDATA.GEN_AI_USAGE_INPUT_TOKENS] == 200
41124112
assert span["attributes"][SPANDATA.GEN_AI_USAGE_OUTPUT_TOKENS] == 50
@@ -4158,7 +4158,7 @@ def test_input_tokens_include_cache_write_nonstreaming(sentry_init, capture_item
41584158
model="claude-sonnet-4-20250514",
41594159
)
41604160

4161-
(span,) = [item.payload for item in items if item.type == "span"]
4161+
(span,) = (item.payload for item in items if item.type == "span")
41624162

41634163
# input_tokens should be total: 19 (non-cached) + 2846 (cache_write) = 2865
41644164
assert span["attributes"][SPANDATA.GEN_AI_USAGE_INPUT_TOKENS] == 2865
@@ -4281,7 +4281,7 @@ def test_input_tokens_include_cache_read_streaming(
42814281
):
42824282
pass
42834283

4284-
(span,) = [item.payload for item in items if item.type == "span"]
4284+
(span,) = (item.payload for item in items if item.type == "span")
42854285

42864286
# input_tokens should be total: 19 + 2846 = test_stream_messages_input_tokens_include_cache_read_streaming
42874287
assert span["attributes"][SPANDATA.GEN_AI_USAGE_INPUT_TOKENS] == 2865
@@ -4351,7 +4351,7 @@ def test_stream_messages_input_tokens_include_cache_read_streaming(
43514351
for event in stream:
43524352
pass
43534353

4354-
(span,) = [item.payload for item in items if item.type == "span"]
4354+
(span,) = (item.payload for item in items if item.type == "span")
43554355

43564356
# input_tokens should be total: 19 + 2846 = 2865
43574357
assert span["attributes"][SPANDATA.GEN_AI_USAGE_INPUT_TOKENS] == 2865
@@ -4396,7 +4396,7 @@ def test_input_tokens_unchanged_without_caching(sentry_init, capture_items):
43964396
model="claude-sonnet-4-20250514",
43974397
)
43984398

4399-
(span,) = [item.payload for item in items if item.type == "span"]
4399+
(span,) = (item.payload for item in items if item.type == "span")
44004400

44014401
assert span["attributes"][SPANDATA.GEN_AI_USAGE_INPUT_TOKENS] == 20
44024402
assert span["attributes"][SPANDATA.GEN_AI_USAGE_TOTAL_TOKENS] == 32 # 20 + 12
@@ -4460,7 +4460,7 @@ def test_cache_tokens_streaming(
44604460
):
44614461
pass
44624462

4463-
(span,) = [item.payload for item in items if item.type == "span"]
4463+
(span,) = (item.payload for item in items if item.type == "span")
44644464
# input_tokens normalized: 100 + 80 (cache_read) + 20 (cache_write) = 200
44654465
assert span["attributes"][SPANDATA.GEN_AI_USAGE_INPUT_TOKENS] == 200
44664466
assert span["attributes"][SPANDATA.GEN_AI_USAGE_OUTPUT_TOKENS] == 10
@@ -4524,7 +4524,7 @@ def test_stream_messages_cache_tokens(
45244524
for event in stream:
45254525
pass
45264526

4527-
(span,) = [item.payload for item in items if item.type == "span"]
4527+
(span,) = (item.payload for item in items if item.type == "span")
45284528
# input_tokens normalized: 100 + 80 (cache_read) + 20 (cache_write) = 200
45294529
assert span["attributes"][SPANDATA.GEN_AI_USAGE_INPUT_TOKENS] == 200
45304530
assert span["attributes"][SPANDATA.GEN_AI_USAGE_OUTPUT_TOKENS] == 10

tests/integrations/google_genai/test_google_genai.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,6 @@ def test_error_handling(sentry_init, capture_items, mock_genai_client):
400400
config=create_test_config(),
401401
)
402402

403-
# Should have both transaction and error events
404-
assert len([item for item in items if item.type == "transaction"]) == 1
405403
(error_event,) = (item.payload for item in items if item.type == "event")
406404

407405
assert error_event["level"] == "error"
@@ -1122,8 +1120,6 @@ def test_embed_content_error_handling(sentry_init, capture_items, mock_genai_cli
11221120
contents=["This will fail"],
11231121
)
11241122

1125-
# Should have both transaction and error events
1126-
assert len([item for item in items if item.type == "transaction"]) == 1
11271123
(error_event,) = (item.payload for item in items if item.type == "event")
11281124

11291125
assert error_event["level"] == "error"
@@ -1352,8 +1348,6 @@ async def test_async_embed_content_error_handling(
13521348
contents=["This will fail"],
13531349
)
13541350

1355-
# Should have both transaction and error events
1356-
assert len([item for item in items if item.type == "transaction"]) == 1
13571351
(error_event,) = (item.payload for item in items if item.type == "event")
13581352

13591353
assert error_event["level"] == "error"
@@ -2186,9 +2180,7 @@ def test_extract_contents_messages_dict_inline_data():
21862180
"""Test extract_contents_messages with dict containing inline_data"""
21872181
content_dict = {
21882182
"role": "user",
2189-
"parts": [
2190-
{"inline_data": {"attributes": b"binary_data", "mime_type": "image/gif"}}
2191-
],
2183+
"parts": [{"inline_data": {"data": b"binary_data", "mime_type": "image/gif"}}],
21922184
}
21932185
result = extract_contents_messages(content_dict)
21942186

tests/integrations/langchain/test_langchain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ def test_langchain_error(sentry_init, capture_items):
897897
with start_transaction(), pytest.raises(ValueError):
898898
list(agent_executor.stream({"input": "How many letters in the word eudca"}))
899899

900-
error = next(item.payload for item in items if item.type == "event")
900+
(error,) = (item.payload for item in items if item.type == "event")
901901
assert error["level"] == "error"
902902

903903

@@ -939,7 +939,7 @@ def test_span_status_error(sentry_init, capture_items):
939939
with pytest.raises(ValueError):
940940
list(agent_executor.stream({"input": "How many letters in the word eudca"}))
941941

942-
error = next(item.payload for item in items if item.type == "event")
942+
(error,) = (item.payload for item in items if item.type == "event")
943943
assert error["level"] == "error"
944944

945945
spans = [item.payload for item in items if item.type == "span"]

tests/integrations/openai/test_openai.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,8 +1462,8 @@ def test_span_status_error(sentry_init, capture_items):
14621462
model="some-model", messages=[{"role": "system", "content": "hello"}]
14631463
)
14641464

1465-
(event,) = (item.payload for item in items if item.type == "event")
1466-
assert event["level"] == "error"
1465+
(error,) = (item.payload for item in items if item.type == "event")
1466+
assert error["level"] == "error"
14671467

14681468
spans = [item.payload for item in items if item.type == "span"]
14691469
assert spans[0]["status"] == "error"
@@ -1964,8 +1964,8 @@ def test_span_origin_streaming_chat(sentry_init, capture_items):
19641964

19651965
"".join(map(lambda x: x.choices[0].delta.content, response_stream))
19661966

1967-
(transaction,) = (item.payload for item in items if item.type == "transaction")
1968-
assert transaction["contexts"]["trace"]["origin"] == "manual"
1967+
(event,) = (item.payload for item in items if item.type == "transaction")
1968+
assert event["contexts"]["trace"]["origin"] == "manual"
19691969

19701970
spans = [item.payload for item in items if item.type == "span"]
19711971
assert spans[0]["attributes"]["sentry.origin"] == "auto.ai.openai"

tests/integrations/openai_agents/test_openai_agents.py

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ async def test_agent_invocation_span_no_pii(
204204
span for span in spans if span["attributes"]["sentry.op"] == OP.GEN_AI_CHAT
205205
)
206206

207-
transactions = [item.payload for item in items if item.type == "transaction"]
208-
assert len(transactions) == 1
209-
transaction = transactions[0]
207+
(transaction,) = (item.payload for item in items if item.type == "transaction")
210208
assert transaction["transaction"] == "test_agent workflow"
211209
assert transaction["contexts"]["trace"]["origin"] == "auto.ai.openai_agents"
212210

@@ -354,9 +352,7 @@ async def test_agent_invocation_span(
354352
assert result is not None
355353
assert result.final_output == "Hello, how can I help you?"
356354

357-
transactions = [item.payload for item in items if item.type == "transaction"]
358-
assert len(transactions) == 1
359-
transaction = transactions[0]
355+
(transaction,) = (item.payload for item in items if item.type == "transaction")
360356
assert transaction["transaction"] == "test_agent workflow"
361357
assert transaction["contexts"]["trace"]["origin"] == "auto.ai.openai_agents"
362358

@@ -583,9 +579,7 @@ def test_agent_invocation_span_sync_no_pii(
583579
assert result is not None
584580
assert result.final_output == "Hello, how can I help you?"
585581

586-
transactions = [item.payload for item in items if item.type == "transaction"]
587-
assert len(transactions) == 1
588-
transaction = transactions[0]
582+
(transaction,) = (item.payload for item in items if item.type == "transaction")
589583
assert transaction["transaction"] == "test_agent workflow"
590584
assert transaction["contexts"]["trace"]["origin"] == "auto.ai.openai_agents"
591585

@@ -739,9 +733,7 @@ def test_agent_invocation_span_sync(
739733
assert result is not None
740734
assert result.final_output == "Hello, how can I help you?"
741735

742-
transactions = [item.payload for item in items if item.type == "transaction"]
743-
assert len(transactions) == 1
744-
transaction = transactions[0]
736+
(transaction,) = (item.payload for item in items if item.type == "transaction")
745737
assert transaction["transaction"] == "test_agent workflow"
746738
assert transaction["contexts"]["trace"]["origin"] == "auto.ai.openai_agents"
747739

@@ -1208,9 +1200,7 @@ def simple_test_tool(message: str) -> str:
12081200
run_config=test_run_config,
12091201
)
12101202

1211-
transactions = [item.payload for item in items if item.type == "transaction"]
1212-
assert len(transactions) == 1
1213-
transaction = transactions[0]
1203+
(transaction,) = (item.payload for item in items if item.type == "transaction")
12141204
assert transaction["transaction"] == "test_agent workflow"
12151205
assert transaction["contexts"]["trace"]["origin"] == "auto.ai.openai_agents"
12161206

@@ -1700,9 +1690,7 @@ def simple_test_tool(message: str) -> str:
17001690
run_config=test_run_config,
17011691
)
17021692

1703-
transactions = [item.payload for item in items if item.type == "transaction"]
1704-
assert len(transactions) == 1
1705-
transaction = transactions[0]
1693+
(transaction,) = (item.payload for item in items if item.type == "transaction")
17061694
assert transaction["transaction"] == "test_agent workflow"
17071695
assert transaction["contexts"]["trace"]["origin"] == "auto.ai.openai_agents"
17081696

@@ -1747,16 +1735,12 @@ async def test_error_handling(sentry_init, capture_items, test_agent):
17471735
test_agent, "Test input", run_config=test_run_config
17481736
)
17491737

1750-
error_events = [item.payload for item in items if item.type == "event"]
1751-
assert len(error_events) == 1
1752-
error_event = error_events[0]
1738+
(error_event,) = (item.payload for item in items if item.type == "event")
17531739
assert error_event["exception"]["values"][0]["type"] == "Exception"
17541740
assert error_event["exception"]["values"][0]["value"] == "Model Error"
17551741
assert error_event["exception"]["values"][0]["mechanism"]["type"] == "openai_agents"
17561742

1757-
transactions = [item.payload for item in items if item.type == "transaction"]
1758-
assert len(transactions) == 1
1759-
transaction = transactions[0]
1743+
(transaction,) = (item.payload for item in items if item.type == "transaction")
17601744
assert transaction["transaction"] == "test_agent workflow"
17611745
assert transaction["contexts"]["trace"]["origin"] == "auto.ai.openai_agents"
17621746

@@ -1811,9 +1795,7 @@ async def test_error_captures_input_data(sentry_init, capture_items, test_agent)
18111795
with pytest.raises(InternalServerError, match="Error code: 500"):
18121796
await agents.Runner.run(agent, "Test input", run_config=test_run_config)
18131797

1814-
error_events = [item.payload for item in items if item.type == "event"]
1815-
assert len(error_events) == 1
1816-
error_event = error_events[0]
1798+
(error_event,) = (item.payload for item in items if item.type == "event")
18171799
assert error_event["exception"]["values"][0]["type"] == "InternalServerError"
18181800
assert error_event["exception"]["values"][0]["value"] == "Error code: 500"
18191801

@@ -3574,9 +3556,7 @@ async def test_no_conversation_id_when_not_provided(
35743556

35753557
assert result is not None
35763558

3577-
transactions = [item.payload for item in items if item.type == "transaction"]
3578-
assert len(transactions) == 1
3579-
transaction = transactions[0]
3559+
(transaction,) = (item.payload for item in items if item.type == "transaction")
35803560

35813561
spans = [item.payload for item in items if item.type == "span"]
35823562
invoke_agent_span = next(

tests/integrations/pydantic_ai/test_pydantic_ai.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ async def run_agent(input_text):
798798

799799
# Verify each transaction is separate
800800
events = [item.payload for item in items if item.type == "transaction"]
801+
assert len(events) == 3
801802
for i, transaction in enumerate(events):
802803
assert transaction["transaction"] == "invoke_agent test_agent"
803804

0 commit comments

Comments
 (0)