9
9
10
10
from ddtrace .helpers import get_correlation_ids
11
11
12
- from datadog_lambda .constants import SamplingPriority , TraceHeader , XraySubsegment , XRAY_TRACE_ID_HEADER_NAME
12
+ from datadog_lambda .constants import (
13
+ SamplingPriority ,
14
+ TraceHeader ,
15
+ XraySubsegment ,
16
+ XRAY_TRACE_ID_HEADER_NAME ,
17
+ )
13
18
from datadog_lambda .tracing import (
14
19
extract_dd_trace_context ,
15
20
create_function_execution_span ,
18
23
_convert_xray_trace_id ,
19
24
_convert_xray_entity_id ,
20
25
_convert_xray_sampling ,
21
- _get_context_from_raw_xray_trace_id
26
+ _get_context_from_raw_xray_trace_id ,
22
27
)
23
28
24
29
function_arn = "arn:aws:lambda:us-west-1:123457598159:function:python-layer-test"
25
30
26
- fake_xray_header_value = "Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=1" ;
31
+ fake_xray_header_value = (
32
+ "Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=1"
33
+ )
27
34
fake_xray_header_value_parent_decimal = "10713633173203262661"
28
35
fake_xray_header_value_root_decimal = "3995693151288333088"
29
36
@@ -72,7 +79,11 @@ def test_without_datadog_trace_headers(self):
72
79
self .assertEqual (source , "xray" )
73
80
self .assertDictEqual (
74
81
ctx ,
75
- {"trace-id" : fake_xray_header_value_root_decimal , "parent-id" : fake_xray_header_value_parent_decimal , "sampling-priority" : "2" },
82
+ {
83
+ "trace-id" : fake_xray_header_value_root_decimal ,
84
+ "parent-id" : fake_xray_header_value_parent_decimal ,
85
+ "sampling-priority" : "2" ,
86
+ },
76
87
)
77
88
self .assertDictEqual (
78
89
get_dd_trace_context (),
@@ -93,7 +104,11 @@ def test_with_incomplete_datadog_trace_headers(self):
93
104
self .assertEqual (source , "xray" )
94
105
self .assertDictEqual (
95
106
ctx ,
96
- {"trace-id" : fake_xray_header_value_root_decimal , "parent-id" : fake_xray_header_value_parent_decimal , "sampling-priority" : "2" },
107
+ {
108
+ "trace-id" : fake_xray_header_value_root_decimal ,
109
+ "parent-id" : fake_xray_header_value_parent_decimal ,
110
+ "sampling-priority" : "2" ,
111
+ },
97
112
)
98
113
self .assertDictEqual (
99
114
get_dd_trace_context (),
@@ -122,15 +137,14 @@ def test_with_complete_datadog_trace_headers(self):
122
137
{"trace-id" : "123" , "parent-id" : "321" , "sampling-priority" : "1" },
123
138
)
124
139
self .assertDictEqual (
125
- get_d ,
140
+ get_dd_trace_context () ,
126
141
{
127
142
TraceHeader .TRACE_ID : "123" ,
128
143
TraceHeader .PARENT_ID : fake_xray_header_value_parent_decimal ,
129
144
TraceHeader .SAMPLING_PRIORITY : "1" ,
130
145
},
131
146
)
132
147
133
-
134
148
def test_with_extractor_function (self ):
135
149
def extractor_foo (event , context ):
136
150
foo = event .get ("foo" , {})
@@ -174,6 +188,7 @@ def extractor_foo(event, context):
174
188
def test_graceful_fail_of_extractor_function (self ):
175
189
def extractor_raiser (event , context ):
176
190
raise Exception ("kreator" )
191
+
177
192
lambda_ctx = get_mock_context ()
178
193
ctx , ctx_source = extract_dd_trace_context (
179
194
{
@@ -369,20 +384,27 @@ def test_convert_xray_sampling(self):
369
384
)
370
385
371
386
def test_get_context_from_raw_xray_trace_id (self ):
372
- #example : Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=1
373
- raw_trace_id = "Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=1"
374
- self .assertEqual (_get_context_from_raw_xray_trace_id (raw_trace_id ), {
375
- "trace_id" : "1-5e272390-8c398be037738dc042009320" ,
376
- "id" : "94ae789b969f1cc5" ,
377
- "sampled" : "1"
378
- })
387
+ # example : Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=1
388
+ raw_trace_id = (
389
+ "Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=1"
390
+ )
391
+ self .assertEqual (
392
+ _get_context_from_raw_xray_trace_id (raw_trace_id ),
393
+ {
394
+ "trace_id" : "1-5e272390-8c398be037738dc042009320" ,
395
+ "id" : "94ae789b969f1cc5" ,
396
+ "sampled" : "1" ,
397
+ },
398
+ )
379
399
380
400
def test_get_context_from_raw_xray_trace_id_truncated_trace (self ):
381
- raw_trace_id = "Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5"
401
+ raw_trace_id = (
402
+ "Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5"
403
+ )
382
404
self .assertIsNone (_get_context_from_raw_xray_trace_id (raw_trace_id ))
383
405
384
406
def test_get_context_from_raw_xray_trace_id_truncated_trace (self ):
385
- #example : Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=1
407
+ # example : Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=1
386
408
raw_trace_id = "Ro_xxx_ot=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=1"
387
409
self .assertIsNone (_get_context_from_raw_xray_trace_id (raw_trace_id ))
388
410
0 commit comments