Skip to content

Commit 870ed87

Browse files
APMSVLS-65 first draft of extractor helper function and inclusion in extract_dd_trace_context
1 parent 2389ec3 commit 870ed87

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

datadog_lambda/tracing.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,25 @@ def extract_context_from_step_functions(event, lambda_context):
536536
logger.debug("The Step Functions trace extractor returned with error %s", e)
537537
return extract_context_from_lambda_context(lambda_context)
538538

539+
def extract_context_from_appsync_event(event, lambda_context):
540+
"""
541+
Extract Datadog trace context from an AppSync event. Intended to replace
542+
need for customers to provide custom extractor function in their code.
543+
"""
544+
nested_json = event.get("request", {}).get("headers", {})
545+
trace_id = nested_json.get("x-datadog-trace-id")
546+
parent_id = nested_json.get("x-datadog-parent-id")
547+
sampling_priority = nested_json.get("x-datadog-sampling-priority")
548+
context = Context(
549+
trace_id=int(trace_id),
550+
span_id=int(parent_id),
551+
sampling_priority=int(sampling_priority),
552+
)
553+
554+
if not _is_context_complete(context):
555+
return extract_context_from_lambda_context(lambda_context)
556+
557+
return context
539558

540559
def extract_context_custom_extractor(extractor, event, lambda_context):
541560
"""
@@ -641,6 +660,8 @@ def extract_dd_trace_context(
641660
context = extract_context_from_kinesis_event(event, lambda_context)
642661
elif event_source.equals(EventTypes.STEPFUNCTIONS):
643662
context = extract_context_from_step_functions(event, lambda_context)
663+
elif event_source.equals(EventTypes.APPSYNC):
664+
context = extract_context_from_appsync_event(event, lambda_context)
644665
else:
645666
context = extract_context_from_lambda_context(lambda_context)
646667

0 commit comments

Comments
 (0)