Skip to content

Commit 3d23714

Browse files
clean
1 parent 7a643b4 commit 3d23714

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

datadog_lambda/tracing.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ def extract_context_from_sqs_or_sns_event_or_context(event, lambda_context):
229229
arn = first_record.get("eventSourceARN", "")
230230
if arn:
231231
is_sqs = True
232-
dd_json_data = None
233232
# logic to deal with SNS => SQS event
234233
if "body" in first_record:
235234
body_str = first_record.get("body")
@@ -251,6 +250,7 @@ def extract_context_from_sqs_or_sns_event_or_context(event, lambda_context):
251250
if dd_payload:
252251
# SQS uses dataType and binaryValue/stringValue
253252
# SNS uses Type and Value
253+
dd_json_data = None
254254
dd_json_data_type = dd_payload.get("Type") or dd_payload.get("dataType")
255255
if dd_json_data_type == "Binary":
256256
import base64
@@ -265,21 +265,21 @@ def extract_context_from_sqs_or_sns_event_or_context(event, lambda_context):
265265
"Datadog Lambda Python only supports extracting trace"
266266
"context from String or Binary SQS/SNS message attributes"
267267
)
268-
if dd_json_data:
269-
dd_data = json.loads(dd_json_data)
270-
271-
if is_step_function_event(dd_data):
272-
try:
273-
return (
274-
extract_context_from_step_functions(dd_data, None),
275-
None,
276-
None,
277-
)
278-
except Exception:
279-
logger.debug(
280-
"Failed to extract Step Functions context from SQS/SNS event."
281-
)
282-
return propagator.extract(dd_data), dd_data, arn
268+
if dd_json_data:
269+
dd_data = json.loads(dd_json_data)
270+
271+
if is_step_function_event(dd_data):
272+
try:
273+
return (
274+
extract_context_from_step_functions(dd_data, None),
275+
None,
276+
None,
277+
)
278+
except Exception:
279+
logger.debug(
280+
"Failed to extract Step Functions context from SQS/SNS event."
281+
)
282+
return propagator.extract(dd_data), dd_data, arn
283283
else:
284284
# Handle case where trace context is injected into attributes.AWSTraceHeader
285285
# example: Root=1-654321ab-000000001234567890abcdef;Parent=0123456789abcdef;Sampled=1

0 commit comments

Comments
 (0)