Skip to content

Commit b7bb4ae

Browse files
committed
Fix tests
1 parent 3055f1b commit b7bb4ae

File tree

1 file changed

+90
-71
lines changed

1 file changed

+90
-71
lines changed

tests/integration/test_spans.py

Lines changed: 90 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -470,64 +470,77 @@ def envelope_with_spans(
470470
headers={"metrics_extracted": metrics_extracted, "item_count": 2},
471471
content_type="application/vnd.sentry.items.span.v2+json",
472472
payload=PayloadRef(
473-
json ={"items": [
474-
{
475-
"trace_id": "89143b0763095bd9c9955e8175d1fb23",
476-
"span_id": "a342abb1214ca182",
477-
"name": "my 1st V2 span",
478-
"kind": "unspecified",
479-
"start_timestamp": start.timestamp(),
480-
"end_timestamp": end.timestamp(),
481-
"attributes": {
482-
"sentry.category": {
483-
"type": "string",
484-
"value": "db",
485-
},
486-
"sentry.exclusive_time_nano": {
487-
"type": "integer",
488-
"value": int((end - start).total_seconds() * 1e9),
473+
json={
474+
"items": [
475+
{
476+
"trace_id": "89143b0763095bd9c9955e8175d1fb23",
477+
"span_id": "a342abb1214ca182",
478+
"name": "my 1st V2 span",
479+
"start_timestamp": start.timestamp(),
480+
"end_timestamp": end.timestamp(),
481+
"attributes": {
482+
"sentry.category": {
483+
"type": "string",
484+
"value": "db",
485+
},
486+
"sentry.exclusive_time_nano": {
487+
"type": "integer",
488+
"value": int((end - start).total_seconds() * 1e9),
489+
},
489490
},
491+
"links": [
492+
{
493+
"trace_id": "89143b0763095bd9c9955e8175d1fb24",
494+
"span_id": "e342abb1214ca183",
495+
"sampled": False,
496+
"attributes": {
497+
"link_double_key": {
498+
"type": "double",
499+
"value": 1.23,
500+
},
501+
},
502+
},
503+
],
490504
},
491-
"links": [
492-
{
493-
"trace_id": "89143b0763095bd9c9955e8175d1fb24",
494-
"span_id": "e342abb1214ca183",
495-
"sampled": False,
496-
"attributes": {
497-
"link_double_key": {
498-
"type": "double",
499-
"value": 1.23,
505+
{
506+
"trace_id": "ff62a8b040f340bda5d830223def1d81",
507+
"span_id": "b0429c44b67a3eb2",
508+
"name": "resource.script",
509+
"status": "ok",
510+
"start_timestamp": start.timestamp(),
511+
"end_timestamp": end.timestamp() + 1,
512+
"links": [
513+
{
514+
"trace_id": "99143b0763095bd9c9955e8175d1fb25",
515+
"span_id": "e342abb1214ca183",
516+
"sampled": True,
517+
"attributes": {
518+
"link_bool_key": {
519+
"type": "boolean",
520+
"value": True,
521+
},
500522
},
501523
},
502-
},
503-
],
504-
},
505-
{
506-
"trace_id": "ff62a8b040f340bda5d830223def1d81",
507-
"span_id": "b0429c44b67a3eb2",
508-
"name": "resource.script",
509-
"status": "ok",
510-
"start_timestamp": start.timestamp(),
511-
"end_timestamp": end.timestamp() + 1,
512-
"links": [
513-
{
514-
"trace_id": "99143b0763095bd9c9955e8175d1fb25",
515-
"span_id": "e342abb1214ca183",
516-
"sampled": True,
517-
"attributes": {
518-
"link_bool_key": {"type": "boolean", "value": True},
524+
],
525+
"attributes": {
526+
"browser.name": {"type": "string", "value": "Chrome"},
527+
"sentry.description": {
528+
"type": "string",
529+
"value": "https://example.com/p/blah.js",
530+
},
531+
"sentry.exclusive_time_nano": {
532+
"type": "integer",
533+
"value": 161 * 1e6,
534+
},
535+
# Span with the same `span_id` and `segment_id`, to make sure it is classified as `is_segment`.
536+
"sentry.segment.id": {
537+
"type": "string",
538+
"value": "b0429c44b67a3eb2",
519539
},
520540
},
521-
],
522-
"attributes": {
523-
"browser.name": {"type": "string", "value": "Chrome"},
524-
"sentry.description": {"type": "string", "value": "https://example.com/p/blah.js"},
525-
"sentry.exclusive_time_nano": {"type": "integer", "value": 345 * 1e6 },
526-
# Span with the same `span_id` and `segment_id`, to make sure it is classified as `is_segment`.
527-
"sentry.segment_id": {"type": "string", "value": "b0429c44b67a3eb2"}
528541
},
529-
}
530-
]}
542+
]
543+
}
531544
),
532545
)
533546
)
@@ -775,7 +788,6 @@ def test_span_ingestion(
775788
"exclusive_time_ms": 500.0,
776789
"is_segment": True,
777790
"is_remote": False,
778-
"kind": "unspecified",
779791
"links": [
780792
{
781793
"trace_id": "89143b0763095bd9c9955e8175d1fb24",
@@ -853,7 +865,7 @@ def test_span_ingestion(
853865
},
854866
"description": "https://example.com/p/blah.js",
855867
"duration_ms": 1500,
856-
"exclusive_time_ms": 345.0,
868+
"exclusive_time_ms": 161.0,
857869
"is_segment": True,
858870
"is_remote": False,
859871
"links": [
@@ -1046,7 +1058,7 @@ def test_span_ingestion(
10461058
"tags": {"decision": "keep", "target_project_id": "42"},
10471059
"timestamp": expected_timestamp + 1,
10481060
"type": "c",
1049-
"value": 3.0,
1061+
"value": 4.0,
10501062
},
10511063
{
10521064
"name": "c:spans/usage@none",
@@ -1067,7 +1079,7 @@ def test_span_ingestion(
10671079
"tags": {},
10681080
"timestamp": expected_timestamp + 1,
10691081
"type": "c",
1070-
"value": 3.0,
1082+
"value": 4.0,
10711083
"received_at": time_after(now_timestamp),
10721084
},
10731085
{
@@ -1085,7 +1097,7 @@ def test_span_ingestion(
10851097
},
10861098
"timestamp": expected_timestamp + 1,
10871099
"type": "d",
1088-
"value": [1500.0],
1100+
"value": [1500.0, 1500.0],
10891101
"received_at": time_after(now_timestamp),
10901102
},
10911103
{
@@ -1169,7 +1181,7 @@ def test_span_ingestion(
11691181
},
11701182
"timestamp": expected_timestamp + 1,
11711183
"type": "d",
1172-
"value": [1500.0],
1184+
"value": [1500.0, 1500.0],
11731185
},
11741186
{
11751187
"name": "d:spans/duration_light@millisecond",
@@ -1198,7 +1210,7 @@ def test_span_ingestion(
11981210
"project_id": 42,
11991211
"name": "d:spans/exclusive_time@millisecond",
12001212
"type": "d",
1201-
"value": [345.0],
1213+
"value": [161.0, 345.0],
12021214
"timestamp": expected_timestamp + 1,
12031215
"tags": {
12041216
"file_extension": "js",
@@ -1271,7 +1283,7 @@ def test_span_ingestion(
12711283
"project_id": 42,
12721284
"name": "d:spans/exclusive_time_light@millisecond",
12731285
"type": "d",
1274-
"value": [345.0],
1286+
"value": [161.0, 345.0],
12751287
"timestamp": expected_timestamp + 1,
12761288
"tags": {
12771289
"file_extension": "js",
@@ -1318,7 +1330,13 @@ def test_span_ingestion(
13181330
"received_at": time_after(now_timestamp),
13191331
},
13201332
]
1321-
assert [m for m in metrics if ":spans/" in m["name"]] == expected_span_metrics
1333+
1334+
span_metrics = [m for m in metrics if ":spans/" in m["name"]]
1335+
1336+
assert len(span_metrics) == len(expected_span_metrics)
1337+
for actual, expected in zip(span_metrics, expected_span_metrics):
1338+
assert actual == expected
1339+
# assert [m for m in metrics if ":spans/" in m["name"]] == expected_span_metrics
13221340

13231341
# Regardless of whether transactions are extracted, score.total is only converted to a transaction metric once:
13241342
score_total_metrics = [
@@ -1703,7 +1721,7 @@ def test_rate_limit_indexed_consistent(
17031721
project_config["config"]["quotas"] = [
17041722
{
17051723
"categories": ["span_indexed"],
1706-
"limit": 4,
1724+
"limit": 6,
17071725
"window": int(datetime.now(UTC).timestamp()),
17081726
"id": uuid.uuid4(),
17091727
"reasonCode": "indexed_exceeded",
@@ -1726,13 +1744,13 @@ def summarize_outcomes():
17261744

17271745
# First batch passes
17281746
relay.send_envelope(project_id, envelope)
1729-
spans = spans_consumer.get_spans(n=4, timeout=10)
1730-
assert len(spans) == 4
1731-
assert summarize_outcomes() == {(16, 0): 4} # SpanIndexed, Accepted
1747+
spans = spans_consumer.get_spans(n=6, timeout=10)
1748+
assert len(spans) == 6
1749+
assert summarize_outcomes() == {(16, 0): 6} # SpanIndexed, Accepted
17321750

17331751
# Second batch is limited
17341752
relay.send_envelope(project_id, envelope)
1735-
assert summarize_outcomes() == {(16, 2): 4} # SpanIndexed, RateLimited
1753+
assert summarize_outcomes() == {(16, 2): 6} # SpanIndexed, RateLimited
17361754

17371755
spans_consumer.assert_empty()
17381756
outcomes_consumer.assert_empty()
@@ -1877,7 +1895,7 @@ def summarize_outcomes():
18771895

18781896
relay.send_envelope(project_id, envelope)
18791897

1880-
assert summarize_outcomes() == {(12, 2): 4, (16, 2): 4}
1898+
assert summarize_outcomes() == {(12, 2): 6, (16, 2): 6}
18811899

18821900
# We emit transaction metrics from spans for legacy reasons. These are not rate limited.
18831901
# (could be a bug)
@@ -2212,13 +2230,13 @@ def summarize_outcomes(outcomes):
22122230
return counter
22132231

22142232
if sample_rate == 1.0:
2215-
spans = spans_consumer.get_spans(timeout=10, n=4)
2216-
assert len(spans) == 4
2217-
outcomes = outcomes_consumer.get_outcomes(timeout=10, n=4)
2218-
assert summarize_outcomes(outcomes) == {(16, 0): 4} # SpanIndexed, Accepted
2233+
spans = spans_consumer.get_spans(timeout=10, n=6)
2234+
assert len(spans) == 6
2235+
outcomes = outcomes_consumer.get_outcomes(timeout=10, n=6)
2236+
assert summarize_outcomes(outcomes) == {(16, 0): 6} # SpanIndexed, Accepted
22192237
else:
22202238
outcomes = outcomes_consumer.get_outcomes(timeout=10, n=1)
2221-
assert summarize_outcomes(outcomes) == {(16, 1): 4} # Span, Filtered
2239+
assert summarize_outcomes(outcomes) == {(16, 1): 6} # Span, Filtered
22222240
assert {o["reason"] for o in outcomes} == {"Sampled:3000"}
22232241

22242242
spans_consumer.assert_empty()
@@ -2477,6 +2495,7 @@ def test_scrubs_ip_addresses(
24772495

24782496
spans_consumer.assert_empty()
24792497

2498+
24802499
def test_spans_v2_multiple_containers_not_allowed(
24812500
mini_sentry,
24822501
relay_with_processing,

0 commit comments

Comments
 (0)