@@ -58,11 +58,17 @@ def _get_xray_trace_context():
58
58
return None
59
59
60
60
xray_trace_entity = xray_recorder .get_trace_entity () # xray (sub)segment
61
- return {
61
+ trace_context = {
62
62
"trace-id" : _convert_xray_trace_id (xray_trace_entity .trace_id ),
63
63
"parent-id" : _convert_xray_entity_id (xray_trace_entity .id ),
64
64
"sampling-priority" : _convert_xray_sampling (xray_trace_entity .sampled ),
65
65
}
66
+ logger .debug (
67
+ "Converted trace context %s from X-Ray segment %s" ,
68
+ trace_context ,
69
+ (xray_trace_entity .trace_id , xray_trace_entity .id , xray_trace_entity .sampled ),
70
+ )
71
+ return trace_context
66
72
67
73
68
74
def _get_dd_trace_py_context ():
@@ -73,6 +79,9 @@ def _get_dd_trace_py_context():
73
79
parent_id = span .context .span_id
74
80
trace_id = span .context .trace_id
75
81
sampling_priority = span .context .sampling_priority
82
+ logger .debug (
83
+ "found dd trace context: %s" , (span .context .trace_id , span .context .span_id )
84
+ )
76
85
return {
77
86
"parent-id" : str (parent_id ),
78
87
"trace-id" : str (trace_id ),
@@ -170,7 +179,11 @@ def extract_context_custom_extractor(extractor, event, lambda_context):
170
179
Extract Datadog trace context using a custom trace extractor function
171
180
"""
172
181
try :
173
- (trace_id , parent_id , sampling_priority ,) = extractor (event , lambda_context )
182
+ (
183
+ trace_id ,
184
+ parent_id ,
185
+ sampling_priority ,
186
+ ) = extractor (event , lambda_context )
174
187
return trace_id , parent_id , sampling_priority
175
188
except Exception as e :
176
189
logger .debug ("The trace extractor returned with error %s" , e )
@@ -189,9 +202,11 @@ def extract_dd_trace_context(event, lambda_context, extractor=None):
189
202
trace_context_source = None
190
203
191
204
if extractor is not None :
192
- (trace_id , parent_id , sampling_priority ,) = extract_context_custom_extractor (
193
- extractor , event , lambda_context
194
- )
205
+ (
206
+ trace_id ,
207
+ parent_id ,
208
+ sampling_priority ,
209
+ ) = extract_context_custom_extractor (extractor , event , lambda_context )
195
210
elif "headers" in event :
196
211
(
197
212
trace_id ,
@@ -258,11 +273,11 @@ def get_dd_trace_context():
258
273
elif xray_context and dd_trace_context :
259
274
context = dd_trace_context .copy ()
260
275
context ["parent-id" ] = xray_context ["parent-id" ]
276
+ logger .debug ("Set parent id from xray trace context: %s" , context ["parent-id" ])
261
277
262
278
if dd_tracing_enabled :
263
279
dd_trace_py_context = _get_dd_trace_py_context ()
264
280
if dd_trace_py_context is not None :
265
- logger .debug ("get_dd_trace_context using dd-trace context" )
266
281
context = dd_trace_py_context
267
282
268
283
return _context_obj_to_headers (context ) if context is not None else {}
@@ -328,9 +343,13 @@ def is_lambda_context():
328
343
329
344
def set_dd_trace_py_root (trace_context_source , merge_xray_traces ):
330
345
if trace_context_source == TraceContextSource .EVENT or merge_xray_traces :
331
- headers = get_dd_trace_context ( )
346
+ headers = _context_obj_to_headers ( dd_trace_context )
332
347
span_context = propagator .extract (headers )
333
348
tracer .context_provider .activate (span_context )
349
+ logger .debug (
350
+ "Set dd trace root context to: %s" ,
351
+ (span_context .trace_id , span_context .span_id ),
352
+ )
334
353
335
354
336
355
def create_function_execution_span (
0 commit comments