Skip to content

Commit 3f207f7

Browse files
Remove spanId from outbound tracestate header (#1771)
* Remove spanId from outbound tracestate header * Remove span id assertion from dt header validator * Remove spanId tracestate assertion from grpc tests --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 853d8cd commit 3f207f7

6 files changed

Lines changed: 58 additions & 35 deletions

File tree

newrelic/common/encoding_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,8 @@ def text(self):
477477
pr = f"{pr:.6f}".rstrip("0").rstrip(".")
478478
version = self.get("v", "0")
479479
ty = "0" # Hardcode this as it will always be App.
480-
payload = f"{version}-{ty}-{self['ac']}-{self['ap']}-{self.get('id', '')}-{self.get('tx', '')}-{'1' if self.get('sa') else '0'}-{pr}-{self['ti']!s}"
480+
# Do not send the span id-this has been deprecated.
481+
payload = f"{version}-{ty}-{self['ac']}-{self['ap']}--{self.get('tx', '')}-{'1' if self.get('sa') else '0'}-{pr}-{self['ti']!s}"
481482
return f"{self.get('tk', self['ac'])}@nr={payload}"
482483

483484
@classmethod

tests/agent_features/test_asgi_w3c_trace_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def _test():
118118
"0.4" if inbound_nr_tracestate else "1.2",
119119
]
120120

121-
assert len(fields[4]) == 16
121+
assert len(fields[4]) == 0
122122
assert len(fields[5]) == 16
123123

124124

tests/agent_features/test_w3c_trace_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def _test():
109109
"0.4" if inbound_nr_tracestate else "1.2",
110110
]
111111

112-
assert len(fields[4]) == 16
112+
assert len(fields[4]) == 0
113113
assert len(fields[5]) == 16
114114

115115

tests/cross_agent/fixtures/distributed_tracing/trace_context.json

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -998,10 +998,12 @@
998998
},
999999
"expected": [
10001000
"traceparent.parent_id",
1001-
"tracestate.span_id",
10021001
"tracestate.transaction_id",
10031002
"tracestate.timestamp",
10041003
"tracestate.parent_application_id"
1004+
],
1005+
"unexpected": [
1006+
"tracestate.span_id"
10051007
]
10061008
}
10071009
],
@@ -1131,9 +1133,11 @@
11311133
"traceparent.parent_id",
11321134
"tracestate.timestamp",
11331135
"tracestate.parent_application_id",
1134-
"tracestate.span_id",
11351136
"tracestate.transaction_id"
11361137
],
1138+
"unexpected": [
1139+
"tracestate.span_id"
1140+
],
11371141
"notequal": {
11381142
"traceparent.parent_id": "7d3efb1b173fecfa"
11391143
}
@@ -1560,10 +1564,12 @@
15601564
},
15611565
"expected": [
15621566
"traceparent.parent_id",
1563-
"tracestate.span_id",
15641567
"tracestate.transaction_id",
15651568
"tracestate.timestamp",
15661569
"tracestate.parent_application_id"
1570+
],
1571+
"unexpected": [
1572+
"tracestate.span_id"
15671573
]
15681574
}
15691575
],
@@ -1638,10 +1644,12 @@
16381644
},
16391645
"expected": [
16401646
"traceparent.parent_id",
1641-
"tracestate.span_id",
16421647
"tracestate.transaction_id",
16431648
"tracestate.timestamp",
16441649
"tracestate.parent_application_id"
1650+
],
1651+
"unexpected": [
1652+
"tracestate.span_id"
16451653
]
16461654
},
16471655
{
@@ -1658,10 +1666,12 @@
16581666
},
16591667
"expected": [
16601668
"traceparent.parent_id",
1661-
"tracestate.span_id",
16621669
"tracestate.transaction_id",
16631670
"tracestate.timestamp",
16641671
"tracestate.parent_application_id"
1672+
],
1673+
"unexpected": [
1674+
"tracestate.span_id"
16651675
]
16661676
}
16671677
],
@@ -1736,10 +1746,12 @@
17361746
},
17371747
"expected": [
17381748
"traceparent.parent_id",
1739-
"tracestate.span_id",
17401749
"tracestate.transaction_id",
17411750
"tracestate.timestamp",
17421751
"tracestate.parent_application_id"
1752+
],
1753+
"unexpected": [
1754+
"tracestate.span_id"
17431755
]
17441756
}
17451757
],
@@ -1901,10 +1913,12 @@
19011913
},
19021914
"expected": [
19031915
"traceparent.parent_id",
1904-
"tracestate.span_id",
19051916
"tracestate.transaction_id",
19061917
"tracestate.timestamp",
19071918
"tracestate.parent_application_id"
1919+
],
1920+
"unexpected": [
1921+
"tracestate.span_id"
19081922
]
19091923
}
19101924
],
@@ -2217,13 +2231,15 @@
22172231
"expected": [
22182232
"traceparent.trace_flags",
22192233
"traceparent.parent_id",
2220-
"tracestate.span_id",
22212234
"tracestate.transaction_id",
22222235
"tracestate.parent_application_id",
22232236
"tracestate.timestamp",
22242237
"tracestate.sampled",
22252238
"tracestate.priority"
22262239
],
2240+
"unexpected": [
2241+
"tracestate.span_id"
2242+
],
22272243
"vendors": [
22282244
"foo",
22292245
"bar"
@@ -2301,12 +2317,14 @@
23012317
"expected": [
23022318
"traceparent.trace_flags",
23032319
"traceparent.parent_id",
2304-
"tracestate.span_id",
23052320
"tracestate.transaction_id",
23062321
"tracestate.parent_application_id",
23072322
"tracestate.timestamp",
23082323
"tracestate.sampled",
23092324
"tracestate.priority"
2325+
],
2326+
"unexpected": [
2327+
"tracestate.span_id"
23102328
]
23112329
}
23122330
],
@@ -2382,13 +2400,15 @@
23822400
"traceparent.trace_id",
23832401
"traceparent.trace_flags",
23842402
"traceparent.parent_id",
2385-
"tracestate.span_id",
23862403
"tracestate.transaction_id",
23872404
"tracestate.parent_application_id",
23882405
"tracestate.timestamp",
23892406
"tracestate.sampled",
23902407
"tracestate.priority"
23912408
],
2409+
"unexpected": [
2410+
"tracestate.span_id"
2411+
],
23922412
"vendors": [
23932413
]
23942414
}
@@ -2423,12 +2443,14 @@
24232443
"traceparent.trace_id",
24242444
"traceparent.trace_flags",
24252445
"traceparent.parent_id",
2426-
"tracestate.span_id",
24272446
"tracestate.transaction_id",
24282447
"tracestate.parent_application_id",
24292448
"tracestate.timestamp",
24302449
"tracestate.sampled",
24312450
"tracestate.priority"
2451+
],
2452+
"unexpected": [
2453+
"tracestate.span_id"
24322454
]
24332455
}
24342456
],
@@ -2467,11 +2489,13 @@
24672489
"expected": [
24682490
"traceparent.trace_flags",
24692491
"traceparent.parent_id",
2470-
"tracestate.span_id",
24712492
"tracestate.transaction_id",
24722493
"tracestate.parent_application_id",
24732494
"tracestate.timestamp"
24742495
],
2496+
"unexpected": [
2497+
"tracestate.span_id"
2498+
],
24752499
"vendors": [
24762500
"44@nr"
24772501
]
@@ -2546,11 +2570,14 @@
25462570
"expected": [
25472571
"traceparent.trace_flags",
25482572
"traceparent.parent_id",
2549-
"tracestate.span_id",
25502573
"tracestate.transaction_id",
25512574
"tracestate.parent_application_id",
25522575
"tracestate.timestamp"
2553-
] }
2576+
],
2577+
"unexpected": [
2578+
"tracestate.span_id"
2579+
]
2580+
}
25542581
],
25552582
"intrinsics": {
25562583
"target_events": ["Transaction"],
@@ -2825,15 +2852,14 @@
28252852
"traceparent.parent_id",
28262853
"tracestate.timestamp",
28272854
"tracestate.parent_application_id",
2828-
"tracestate.span_id",
28292855
"tracestate.transaction_id",
28302856
"newrelic.d.ap",
28312857
"newrelic.d.tx",
28322858
"newrelic.d.ti",
28332859
"newrelic.d.id",
28342860
"newrelic.d.pr"
28352861
],
2836-
"unexpected": ["newrelic.d.tk"]
2862+
"unexpected": ["tracestate.span_id", "newrelic.d.tk"]
28372863
}
28382864
],
28392865
"intrinsics": {
@@ -2904,12 +2930,11 @@
29042930
},
29052931
"expected": [
29062932
"traceparent.parent_id",
2907-
"tracestate.span_id",
29082933
"tracestate.timestamp",
29092934
"tracestate.parent_application_id"
29102935
],
29112936
"unexpected": [
2912-
"tracestate.transaction_id"
2937+
"tracestate.span_id", "tracestate.transaction_id"
29132938
]
29142939
}
29152940
],
@@ -3035,7 +3060,6 @@
30353060
"expected": [
30363061
"traceparent.trace_flags",
30373062
"traceparent.parent_id",
3038-
"tracestate.span_id",
30393063
"tracestate.transaction_id",
30403064
"tracestate.parent_application_id",
30413065
"tracestate.timestamp",
@@ -3044,7 +3068,7 @@
30443068
"newrelic.d.ti",
30453069
"newrelic.d.id"
30463070
],
3047-
"unexpected": ["newrelic.d.tk"]
3071+
"unexpected": ["tracestate.span_id", "newrelic.d.tk"]
30483072
}
30493073
],
30503074
"expected_metrics": [
@@ -3088,10 +3112,12 @@
30883112
"expected": [
30893113
"traceparent.trace_flags",
30903114
"traceparent.parent_id",
3091-
"tracestate.span_id",
30923115
"tracestate.transaction_id",
30933116
"tracestate.parent_application_id",
30943117
"tracestate.timestamp"
3118+
],
3119+
"unexpected": [
3120+
"tracestate.span_id"
30953121
]
30963122
}
30973123
],
@@ -3141,7 +3167,6 @@
31413167
"expected": [
31423168
"traceparent.trace_flags",
31433169
"traceparent.parent_id",
3144-
"tracestate.span_id",
31453170
"tracestate.transaction_id",
31463171
"tracestate.parent_application_id",
31473172
"tracestate.timestamp",
@@ -3150,7 +3175,7 @@
31503175
"newrelic.d.ti",
31513176
"newrelic.d.id"
31523177
],
3153-
"unexpected": ["newrelic.d.tk"]
3178+
"unexpected": ["tracestate.span_id", "newrelic.d.tk"]
31543179
}
31553180
],
31563181
"expected_metrics": [

tests/framework_grpc/test_distributed_tracing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ def _test():
129129
# The external span should be the parent
130130
exact_intrinsics["guid"] = w3c_parent["id"]
131131

132-
# Check that tracestate and traceparent agree on the span id / sampled flag
133-
assert nr_tracestate["id"] == w3c_parent["id"]
132+
# Check that traceparent contains the span id
133+
assert w3c_parent["id"]
134+
# Check that tracestate and traceparent agree on the sampled flag
134135
assert nr_tracestate["sa"] == w3c_parent["sa"]
135136

136137
_test()

tests/testing_support/validators/validate_distributed_tracing_header.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,9 @@ def validate_distributed_tracing_header():
6868
# Verify data belonging to this transaction
6969
assert data["tx"] == transaction.guid
7070

71-
# If span events are enabled, id should be sent
72-
# otherwise, id should be omitted
73-
if transaction.settings.span_events.enabled:
74-
assert "id" in data
75-
assert data["id"] == w3c_parent["id"]
76-
else:
77-
assert "id" not in data
71+
# span id should not ever be sent.
72+
assert "id" not in data
73+
assert w3c_parent["id"]
7874

7975
# Verify timestamp is an integer
8076
assert isinstance(data["ti"], int)

0 commit comments

Comments
 (0)