@@ -75,10 +75,10 @@ def _extract_context(context_json, event_type, arn):
7575 """
7676 context = propagator .extract (context_json )
7777
78- if not _is_context_complete ( context ) :
78+ if not config . data_streams_enabled :
7979 return context
8080
81- if not config . data_streams_enabled :
81+ if not _is_context_complete ( context ) :
8282 return context
8383 try :
8484 carrier_get = _create_carrier_get (context_json )
@@ -246,7 +246,6 @@ def extract_context_from_sqs_or_sns_event_or_context(event, lambda_context):
246246 Falls back to lambda context if no trace data is found in the SQS message attributes.
247247 """
248248 is_sqs = False
249- arn = None
250249
251250 # EventBridge => SQS
252251 try :
@@ -276,6 +275,7 @@ def extract_context_from_sqs_or_sns_event_or_context(event, lambda_context):
276275 msg_attributes = first_record .get ("messageAttributes" )
277276 if msg_attributes is None :
278277 sns_record = first_record .get ("Sns" ) or {}
278+ arn = sns_record .get ("TopicArn" , "" )
279279 msg_attributes = sns_record .get ("MessageAttributes" ) or {}
280280 dd_payload = msg_attributes .get ("_datadog" )
281281 if dd_payload :
@@ -307,9 +307,7 @@ def extract_context_from_sqs_or_sns_event_or_context(event, lambda_context):
307307 logger .debug (
308308 "Failed to extract Step Functions context from SQS/SNS event."
309309 )
310- if is_sqs :
311- return _extract_context (dd_data , "sqs" , arn )
312- return _extract_context (dd_data , "sns" , sns_record .get ("TopicArn" , "" ))
310+ return _extract_context (dd_data , "sqs" if is_sqs else "sns" , arn )
313311 else :
314312 # Handle case where trace context is injected into attributes.AWSTraceHeader
315313 # example: Root=1-654321ab-000000001234567890abcdef;Parent=0123456789abcdef;Sampled=1
0 commit comments