-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest_128_bit_traceids.py
637 lines (572 loc) · 30.1 KB
/
test_128_bit_traceids.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
import pytest
from utils.parametric.spec.trace import find_first_span_in_trace_payload, find_trace, find_only_span
from utils import missing_feature, context, scenarios, features
parametrize = pytest.mark.parametrize
POWER_2_64 = 18446744073709551616
@scenarios.parametric
@features.trace_id_128_bit_generation_propagation
class Test_128_Bit_Traceids:
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "Datadog", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "false"}],
)
def test_datadog_128_bit_propagation(self, test_agent, test_library):
"""Ensure that external 128-bit TraceIds are properly propagated in Datadog
headers.
"""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers(
[
["x-datadog-trace-id", "1234567890123456789"],
["x-datadog-parent-id", "987654321"],
["x-datadog-tags", "_dd.p.tid=640cfd8d00000000"],
],
)
span = find_only_span(test_agent.wait_for_num_traces(1))
trace_id = span.get("trace_id")
dd_p_tid = span["meta"].get("_dd.p.tid")
assert trace_id == 1234567890123456789
assert int(headers["x-datadog-trace-id"], 10) == trace_id
assert dd_p_tid == "640cfd8d00000000"
assert "_dd.p.tid=" + dd_p_tid in headers["x-datadog-tags"]
@missing_feature(context.library == "nodejs", reason="not implemented")
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "Datadog", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "false"}],
)
def test_datadog_128_bit_propagation_tid_long(self, test_agent, test_library):
"""Ensure that incoming tids that are too long are discarded."""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers(
[
["x-datadog-trace-id", "1234567890123456789"],
["x-datadog-parent-id", "987654321"],
["x-datadog-tags", "_dd.p.tid=1234567890abcdef1"],
],
)
span = find_only_span(test_agent.wait_for_num_traces(1))
trace_id = span.get("trace_id")
dd_p_tid = span["meta"].get("_dd.p.tid")
assert trace_id == 1234567890123456789
assert int(headers["x-datadog-trace-id"], 10) == trace_id
assert dd_p_tid is None
assert "x-datadog-tags" not in headers or "_dd.p.tid=" not in headers["x-datadog-tags"]
@missing_feature(context.library == "nodejs", reason="not implemented")
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "Datadog", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "false"}],
)
def test_datadog_128_bit_propagation_tid_short(self, test_agent, test_library):
"""Ensure that incoming tids that are too short are discarded."""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers(
[
["x-datadog-trace-id", "1234567890123456789"],
["x-datadog-parent-id", "987654321"],
["x-datadog-tags", "_dd.p.tid=1234567890abcde"],
],
)
span = find_only_span(test_agent.wait_for_num_traces(1))
trace_id = span.get("trace_id")
dd_p_tid = span["meta"].get("_dd.p.tid")
assert trace_id == 1234567890123456789
assert int(headers["x-datadog-trace-id"], 10) == trace_id
assert dd_p_tid is None
assert "x-datadog-tags" not in headers or "_dd.p.tid=" not in headers["x-datadog-tags"]
@missing_feature(context.library == "nodejs", reason="not implemented")
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "Datadog", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "false"}],
)
def test_datadog_128_bit_propagation_tid_chars(self, test_agent, test_library):
"""Ensure that incoming tids with bad characters are discarded."""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers(
[
["x-datadog-trace-id", "1234567890123456789"],
["x-datadog-parent-id", "987654321"],
["x-datadog-tags", "_dd.p.tid=1234567890abcdeX"],
],
)
span = find_only_span(test_agent.wait_for_num_traces(1))
trace_id = span.get("trace_id")
dd_p_tid = span["meta"].get("_dd.p.tid")
assert trace_id == 1234567890123456789
assert int(headers["x-datadog-trace-id"], 10) == trace_id
assert dd_p_tid is None
assert "x-datadog-tags" not in headers or "_dd.p.tid=" not in headers["x-datadog-tags"]
@missing_feature(context.library == "dotnet", reason="Optional feature not implemented")
@missing_feature(context.library == "golang", reason="Optional feature not implemented")
@missing_feature(context.library == "nodejs", reason="not implemented")
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "Datadog", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "false"}],
)
def test_datadog_128_bit_propagation_tid_malformed_optional_tag(self, test_agent, test_library):
"""Ensure that if incoming tids are malformed and the error is tagged, the tag is set to the expected value."""
with test_library:
test_library.dd_make_child_span_and_get_headers(
[
["x-datadog-trace-id", "1234567890123456789"],
["x-datadog-parent-id", "987654321"],
["x-datadog-tags", "_dd.p.tid=XXXX"],
],
)
assert (
find_only_span(test_agent.wait_for_num_traces(1))["meta"].get("_dd.propagation_error")
== "malformed_tid XXXX"
)
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "Datadog", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "true"}],
)
def test_datadog_128_bit_propagation_and_generation(self, test_agent, test_library):
"""Ensure that a new span from incoming headers does not modify the trace id when generation is true."""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers(
[["x-datadog-trace-id", "1234567890123456789"], ["x-datadog-parent-id", "987654321"]],
)
span = find_only_span(test_agent.wait_for_num_traces(1))
trace_id = span.get("trace_id")
dd_p_tid = span["meta"].get("_dd.p.tid")
assert trace_id == 1234567890123456789
assert int(headers["x-datadog-trace-id"], 10) == trace_id
assert dd_p_tid is None
assert "x-datadog-tags" not in headers or "_dd.p.tid=" not in headers["x-datadog-tags"]
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "Datadog", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "false"}],
)
def test_datadog_128_bit_generation_disabled(self, test_agent, test_library):
"""Ensure that 64-bit TraceIds are properly generated, propagated in
datadog headers, and populated in trace data.
"""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers([])
span = find_only_span(test_agent.wait_for_num_traces(1))
trace_id = span.get("trace_id")
dd_p_tid = span["meta"].get("_dd.p.tid")
assert trace_id < POWER_2_64
assert int(headers["x-datadog-trace-id"], 10) == trace_id
assert dd_p_tid is None
assert "x-datadog-tags" not in headers or "_dd.p.tid=" not in headers["x-datadog-tags"]
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "Datadog", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "true"}],
)
def test_datadog_128_bit_generation_enabled(self, test_agent, test_library):
"""Ensure that 128-bit TraceIds are properly generated, propagated in
datadog headers, and populated in trace data.
"""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers([])
span = find_only_span(test_agent.wait_for_num_traces(1))
trace_id = span.get("trace_id")
dd_p_tid = span["meta"].get("_dd.p.tid")
assert trace_id < POWER_2_64
assert int(headers["x-datadog-trace-id"], 10) == trace_id
assert "_dd.p.tid=" + dd_p_tid in headers["x-datadog-tags"]
validate_dd_p_tid(dd_p_tid)
@missing_feature(context.library == "golang", reason="not implemented")
@missing_feature(context.library < "[email protected]", reason="Implemented in 1.24.0")
@missing_feature(context.library < "[email protected]", reason="Implemented in 4.19.0 & 3.40.0")
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize("library_env", [{"DD_TRACE_PROPAGATION_STYLE": "Datadog"}])
def test_datadog_128_bit_generation_enabled_by_default(self, test_agent, test_library):
"""Ensure that 128-bit TraceIds are properly generated, propagated in
datadog headers, and populated in trace data.
"""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers([])
span = find_only_span(test_agent.wait_for_num_traces(1))
trace_id = span.get("trace_id")
dd_p_tid = span["meta"].get("_dd.p.tid")
assert trace_id < POWER_2_64
assert int(headers["x-datadog-trace-id"], 10) == trace_id
assert "_dd.p.tid=" + dd_p_tid in headers["x-datadog-tags"]
validate_dd_p_tid(dd_p_tid)
@missing_feature(context.library == "cpp", reason="propagation style not supported")
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "B3 single header", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "false"}],
)
def test_b3single_128_bit_propagation(self, test_agent, test_library):
"""Ensure that external 128-bit TraceIds are properly propagated in B3
single-header.
"""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers(
[["b3", "640cfd8d00000000abcdefab12345678-000000003ade68b1-1"]],
)
span = find_only_span(test_agent.wait_for_num_traces(1))
trace_id = span.get("trace_id")
dd_p_tid = span["meta"].get("_dd.p.tid")
fields = headers["b3"].split("-", 1)
assert trace_id == int("abcdefab12345678", 16)
assert dd_p_tid == "640cfd8d00000000"
check_128_bit_trace_id(fields[0], trace_id, dd_p_tid)
@missing_feature(context.library == "cpp", reason="propagation style not supported")
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "B3 single header", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "true"}],
)
def test_b3single_128_bit_propagation_and_generation(self, test_agent, test_library):
"""Ensure that a new span from incoming headers does not modify the trace id when generation is true."""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers([["b3", "abcdefab12345678-000000003ade68b1-1"]])
span = find_only_span(test_agent.wait_for_num_traces(1))
trace_id = span.get("trace_id")
dd_p_tid = span["meta"].get("_dd.p.tid")
fields = headers["b3"].split("-", 1)
assert trace_id == int("abcdefab12345678", 16)
assert dd_p_tid is None
check_64_bit_trace_id(fields[0], trace_id, dd_p_tid)
@missing_feature(context.library == "cpp", reason="propagation style not supported")
@missing_feature(
context.library == "ruby", reason="Issue: Ruby doesn't support case-insensitive distributed headers"
)
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "B3 single header", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "false"}],
)
def test_b3single_128_bit_generation_disabled(self, test_agent, test_library):
"""Ensure that 64-bit TraceIds are properly generated, propagated in B3
single-header, and populated in trace data.
"""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers([])
span = find_only_span(test_agent.wait_for_num_traces(1))
fields = headers["b3"].split("-", 1)
check_64_bit_trace_id(fields[0], span.get("trace_id"), span["meta"].get("_dd.p.tid"))
@missing_feature(context.library == "cpp", reason="propagation style not supported")
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "B3 single header", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "true"}],
)
def test_b3single_128_bit_generation_enabled(self, test_agent, test_library):
"""Ensure that 128-bit TraceIds are properly generated, propagated in B3
single-header, and populated in trace data.
"""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers([])
span = find_only_span(test_agent.wait_for_num_traces(1))
fields = headers["b3"].split("-", 1)
check_128_bit_trace_id(fields[0], span.get("trace_id"), span["meta"].get("_dd.p.tid"))
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "b3multi", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "false"}],
)
def test_b3multi_128_bit_propagation(self, test_agent, test_library):
"""Ensure that external 128-bit TraceIds are properly propagated in B3
multi-headers.
"""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers(
[["x-b3-traceid", "640cfd8d00000000abcdefab12345678"], ["x-b3-spanid", "000000003ade68b1"]],
)
span = find_only_span(test_agent.wait_for_num_traces(1))
trace_id = span.get("trace_id")
dd_p_tid = span["meta"].get("_dd.p.tid")
assert trace_id == int("abcdefab12345678", 16)
assert dd_p_tid == "640cfd8d00000000"
check_128_bit_trace_id(headers["x-b3-traceid"], trace_id, dd_p_tid)
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "b3multi", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "true"}],
)
def test_b3multi_128_bit_propagation_and_generation(self, test_agent, test_library):
"""Ensure that a new span from incoming headers does not modify the trace id when generation is true."""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers(
[["x-b3-traceid", "abcdefab12345678"], ["x-b3-spanid", "000000003ade68b1"]],
)
span = find_only_span(test_agent.wait_for_num_traces(1))
trace_id = span.get("trace_id")
dd_p_tid = span["meta"].get("_dd.p.tid")
assert trace_id == int("abcdefab12345678", 16)
assert dd_p_tid is None
check_64_bit_trace_id(headers["x-b3-traceid"], trace_id, dd_p_tid)
@missing_feature(
context.library == "ruby", reason="Issue: Ruby doesn't support case-insensitive distributed headers"
)
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "b3multi", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "false"}],
)
def test_b3multi_128_bit_generation_disabled(self, test_agent, test_library):
"""Ensure that 64-bit TraceIds are properly generated, propagated in B3
multi-headers, and populated in trace data.
"""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers([])
span = find_only_span(test_agent.wait_for_num_traces(1))
check_64_bit_trace_id(headers["x-b3-traceid"], span.get("trace_id"), span["meta"].get("_dd.p.tid"))
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "b3multi", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "true"}],
)
def test_b3multi_128_bit_generation_enabled(self, test_agent, test_library):
"""Ensure that 128-bit TraceIds are properly generated, propagated in B3
multi-headers, and populated in trace data.
"""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers([])
span = find_only_span(test_agent.wait_for_num_traces(1))
check_128_bit_trace_id(headers["x-b3-traceid"], span.get("trace_id"), span["meta"].get("_dd.p.tid"))
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "tracecontext", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "false"}],
)
def test_w3c_128_bit_propagation(self, test_agent, test_library):
"""Ensure that external 128-bit TraceIds are properly propagated in W3C
headers.
"""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers(
[["traceparent", "00-640cfd8d00000000abcdefab12345678-000000003ade68b1-01"]],
)
span = find_only_span(test_agent.wait_for_num_traces(1))
trace_id = span.get("trace_id")
dd_p_tid = span["meta"].get("_dd.p.tid")
fields = headers["traceparent"].split("-", 2)
assert trace_id == int("abcdefab12345678", 16)
assert dd_p_tid == "640cfd8d00000000"
check_128_bit_trace_id(fields[1], trace_id, dd_p_tid)
@missing_feature(context.library < "[email protected]", reason="implemented in 5.7.0 & 4.31.0")
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "tracecontext", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "false"}],
)
def test_w3c_128_bit_propagation_tid_consistent(self, test_agent, test_library):
"""Ensure that if the trace state contains a tid that is consistent with the trace id from
the trace header then no error is reported.
"""
with test_library:
test_library.dd_make_child_span_and_get_headers(
[
["traceparent", "00-640cfd8d00000000abcdefab12345678-000000003ade68b1-01"],
["tracestate", "dd=t.tid:640cfd8d00000000"],
],
)
span = find_only_span(test_agent.wait_for_num_traces(1))
trace_id = span.get("trace_id")
dd_p_tid = span["meta"].get("_dd.p.tid")
propagation_error = span["meta"].get("_dd.propagation_error")
assert trace_id == int("abcdefab12345678", 16)
assert dd_p_tid == "640cfd8d00000000"
assert propagation_error is None
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "tracecontext", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "true"}],
)
def test_w3c_128_bit_propagation_tid_in_chunk_root(self, test_agent, test_library):
"""Ensure that only root span contains the tid."""
with test_library:
with test_library.dd_start_span(name="parent", service="service", resource="resource") as parent:
with test_library.dd_start_span(name="child", service="service", parent_id=parent.span_id) as child:
pass
traces = test_agent.wait_for_num_traces(1, clear=True, sort_by_start=False)
trace = find_trace(traces, parent.trace_id)
assert len(trace) == 2
first_span = find_first_span_in_trace_payload(trace)
tid_chunk_root = first_span["meta"].get("_dd.p.tid")
assert tid_chunk_root is not None
@missing_feature(context.library == "ruby", reason="not implemented")
@missing_feature(context.library == "java", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "tracecontext", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "true"}],
)
def test_w3c_128_bit_propagation_tid_only_in_chunk_root(self, test_agent, test_library):
"""Ensure that only root span contains the tid."""
with test_library:
with test_library.dd_start_span(name="parent", service="service", resource="resource") as parent:
with test_library.dd_start_span(name="child", service="service", parent_id=parent.span_id) as child:
pass
traces = test_agent.wait_for_num_traces(1, clear=True, sort_by_start=False)
trace = find_trace(traces, parent.trace_id)
assert len(trace) == 2
first_span = find_first_span_in_trace_payload(trace)
spans_with_tid = [span for span in trace if "_dd.p.tid" in span.get("meta", "")]
assert len(spans_with_tid) == 1
assert first_span == spans_with_tid[0]
tid_chunk_root = first_span["meta"].get("_dd.p.tid")
assert tid_chunk_root is not None
@missing_feature(context.library == "nodejs", reason="not implemented")
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "tracecontext", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "false"}],
)
def test_w3c_128_bit_propagation_tid_inconsistent(self, test_agent, test_library):
"""Ensure that if the trace state contains a tid that is inconsistent with the trace id from
the trace header, the trace header tid is preserved.
"""
with test_library:
test_library.dd_make_child_span_and_get_headers(
[
["traceparent", "00-640cfd8d00000000abcdefab12345678-000000003ade68b1-01"],
["tracestate", "dd=t.tid:640cfd8d0000ffff"],
],
)
span = find_only_span(test_agent.wait_for_num_traces(1))
trace_id = span.get("trace_id")
dd_p_tid = span["meta"].get("_dd.p.tid")
assert trace_id == int("abcdefab12345678", 16)
assert dd_p_tid == "640cfd8d00000000"
@missing_feature(context.library == "dotnet", reason="Optional feature not implemented")
@missing_feature(context.library == "golang", reason="Optional feature not implemented")
@missing_feature(context.library == "nodejs", reason="not implemented")
@missing_feature(context.library == "python", reason="inconsistent_tid is not implemented for w3c")
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "tracecontext", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "false"}],
)
def test_w3c_128_bit_propagation_tid_inconsistent_optional_tag(self, test_agent, test_library):
"""Ensure that if the trace state contains a tid that is inconsistent with the trace id from
the trace header the error is tagged.
"""
with test_library:
test_library.dd_make_child_span_and_get_headers(
[
["traceparent", "00-640cfd8d00000000abcdefab12345678-000000003ade68b1-01"],
["tracestate", "dd=t.tid:640cfd8d0000ffff"],
],
)
assert (
find_only_span(test_agent.wait_for_num_traces(1))["meta"].get("_dd.propagation_error")
== "inconsistent_tid 640cfd8d0000ffff"
)
@missing_feature(context.library == "nodejs", reason="not implemented")
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "tracecontext", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "false"}],
)
def test_w3c_128_bit_propagation_tid_malformed(self, test_agent, test_library):
"""Ensure that if the trace state contains a tid that is badly formed, the trace header tid is preserved."""
with test_library:
test_library.dd_make_child_span_and_get_headers(
[
["traceparent", "00-640cfd8d00000000abcdefab12345678-000000003ade68b1-01"],
["tracestate", "dd=t.tid:XXXX"],
],
)
span = find_only_span(test_agent.wait_for_num_traces(1))
trace_id = span.get("trace_id")
dd_p_tid = span["meta"].get("_dd.p.tid")
assert trace_id == int("abcdefab12345678", 16)
assert dd_p_tid == "640cfd8d00000000"
@missing_feature(context.library == "dotnet", reason="Optional feature not implemented")
@missing_feature(context.library == "golang", reason="Optional feature not implemented")
@missing_feature(context.library == "nodejs", reason="not implemented")
@missing_feature(context.library == "python", reason="malformed_tid is not implemented")
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "tracecontext", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "false"}],
)
def test_w3c_128_bit_propagation_tid_malformed_optional_tag(self, test_agent, test_library):
"""Ensure that if the trace state contains a tid that is badly formed and the error is tagged,
it is tagged with the expected value.
"""
with test_library:
test_library.dd_make_child_span_and_get_headers(
[
["traceparent", "00-640cfd8d00000000abcdefab12345678-000000003ade68b1-01"],
["tracestate", "dd=t.tid:XXXX"],
],
)
assert (
find_only_span(test_agent.wait_for_num_traces(1))["meta"].get("_dd.propagation_error")
== "malformed_tid XXXX"
)
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "tracecontext", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "true"}],
)
def test_w3c_128_bit_propagation_and_generation(self, test_agent, test_library):
"""Ensure that a new span from incoming headers does not modify the trace id when generation is true."""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers(
[["traceparent", "00-0000000000000000abcdefab12345678-000000003ade68b1-01"]],
)
span = find_only_span(test_agent.wait_for_num_traces(1))
trace_id = span.get("trace_id")
dd_p_tid = span["meta"].get("_dd.p.tid")
fields = headers["traceparent"].split("-", 2)
assert trace_id == int("abcdefab12345678", 16)
assert dd_p_tid is None
check_64_bit_trace_id(fields[1], trace_id, dd_p_tid)
@missing_feature(
context.library == "ruby", reason="Issue: Ruby doesn't support case-insensitive distributed headers"
)
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "tracecontext", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "false"}],
)
def test_w3c_128_bit_generation_disabled(self, test_agent, test_library):
"""Ensure that 64-bit TraceIds are properly generated, propagated in W3C
headers, and populated in trace data.
"""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers([])
span = find_only_span(test_agent.wait_for_num_traces(1))
fields = headers["traceparent"].split("-", 2)
check_64_bit_trace_id(fields[1], span.get("trace_id"), span["meta"].get("_dd.p.tid"))
@missing_feature(context.library == "ruby", reason="not implemented")
@pytest.mark.parametrize(
"library_env",
[{"DD_TRACE_PROPAGATION_STYLE": "tracecontext", "DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED": "true"}],
)
def test_w3c_128_bit_generation_enabled(self, test_agent, test_library):
"""Ensure that 128-bit TraceIds are properly generated, propagated in W3C
headers, and populated in trace data.
"""
with test_library:
headers = test_library.dd_make_child_span_and_get_headers([])
span = find_only_span(test_agent.wait_for_num_traces(1))
fields = headers["traceparent"].split("-", 2)
check_128_bit_trace_id(fields[1], span.get("trace_id"), span["meta"].get("_dd.p.tid"))
ZERO8 = "00000000"
ZERO16 = ZERO8 + ZERO8
def check_64_bit_trace_id(header_trace_id, span_trace_id, dd_p_tid):
"""Ensure that 64-bit TraceIds are properly formatted and populated in
trace data.
"""
assert len(header_trace_id) == 16 or (len(header_trace_id) == 32 and header_trace_id[0:16] == ZERO16)
assert int(header_trace_id, 16) == span_trace_id
assert dd_p_tid is None
def check_128_bit_trace_id(header_trace_id, span_trace_id, dd_p_tid):
"""Ensure that 128-bit TraceIds are well-formed and populated in trace
data.
"""
assert len(header_trace_id) == 32
assert int(header_trace_id[16:32], 16) == span_trace_id
validate_dd_p_tid(dd_p_tid)
assert header_trace_id.startswith(dd_p_tid)
def validate_dd_p_tid(dd_p_tid):
"""Validate that dd_p_tid is well-formed."""
assert not dd_p_tid is None
assert len(dd_p_tid) == 16
assert dd_p_tid != ZERO16
assert dd_p_tid[8:16] == ZERO8
# check that dd_p_tid[0:8] is consistent with a Unix timestamp from after
# 17:15:40 March 11, 2023.
assert int(dd_p_tid[0:8], 16) > 0x640CFD8C