Skip to content

Commit aff4771

Browse files
authored
Fix incorrect parent id of aws.lambda span (#115)
1 parent 689ed6f commit aff4771

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

datadog_lambda/tracing.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,17 @@ def _get_xray_trace_context():
5858
return None
5959

6060
xray_trace_entity = xray_recorder.get_trace_entity() # xray (sub)segment
61-
return {
61+
trace_context = {
6262
"trace-id": _convert_xray_trace_id(xray_trace_entity.trace_id),
6363
"parent-id": _convert_xray_entity_id(xray_trace_entity.id),
6464
"sampling-priority": _convert_xray_sampling(xray_trace_entity.sampled),
6565
}
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
6672

6773

6874
def _get_dd_trace_py_context():
@@ -73,6 +79,9 @@ def _get_dd_trace_py_context():
7379
parent_id = span.context.span_id
7480
trace_id = span.context.trace_id
7581
sampling_priority = span.context.sampling_priority
82+
logger.debug(
83+
"found dd trace context: %s", (span.context.trace_id, span.context.span_id)
84+
)
7685
return {
7786
"parent-id": str(parent_id),
7887
"trace-id": str(trace_id),
@@ -258,11 +267,11 @@ def get_dd_trace_context():
258267
elif xray_context and dd_trace_context:
259268
context = dd_trace_context.copy()
260269
context["parent-id"] = xray_context["parent-id"]
270+
logger.debug("Set parent id from xray trace context: %s", context["parent-id"])
261271

262272
if dd_tracing_enabled:
263273
dd_trace_py_context = _get_dd_trace_py_context()
264274
if dd_trace_py_context is not None:
265-
logger.debug("get_dd_trace_context using dd-trace context")
266275
context = dd_trace_py_context
267276

268277
return _context_obj_to_headers(context) if context is not None else {}
@@ -328,9 +337,13 @@ def is_lambda_context():
328337

329338
def set_dd_trace_py_root(trace_context_source, merge_xray_traces):
330339
if trace_context_source == TraceContextSource.EVENT or merge_xray_traces:
331-
headers = get_dd_trace_context()
340+
headers = _context_obj_to_headers(dd_trace_context)
332341
span_context = propagator.extract(headers)
333342
tracer.context_provider.activate(span_context)
343+
logger.debug(
344+
"Set dd trace root context to: %s",
345+
(span_context.trace_id, span_context.span_id),
346+
)
334347

335348

336349
def create_function_execution_span(

0 commit comments

Comments
 (0)