Skip to content

Commit 45ba945

Browse files
committed
exception handling for timestamp parsing
1 parent 6222016 commit 45ba945

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

datadog_lambda/tracing.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,12 @@ def extract_context_from_eventbridge_event(event, lambda_context):
349349
if not dd_context:
350350
return extract_context_from_lambda_context(lambda_context)
351351

352-
if is_step_function_event(dd_context):
353-
return extract_context_from_step_functions(dd_context, lambda_context)
352+
try:
353+
return extract_context_from_step_functions(dd_context, None)
354+
except Exception:
355+
logger.debug(
356+
"Failed to extract Step Functions context from EventBridge event."
357+
)
354358

355359
return propagator.extract(dd_context)
356360
except Exception as e:
@@ -1322,13 +1326,16 @@ def create_inferred_span_from_eventbridge_event(event, context):
13221326
tag_source="self",
13231327
)
13241328

1329+
timestamp = event.get("time")
1330+
dt_format = "%Y-%m-%dT%H:%M:%SZ"
1331+
13251332
# Use more granular timestamp from upstream Step Function if possible
1326-
if is_step_function_event(event.get("detail")):
1327-
timestamp = event.get("detail").get("_datadog").get("State").get("EnteredTime")
1328-
dt_format = "%Y-%m-%dT%H:%M:%S.%fZ"
1329-
else:
1330-
timestamp = event.get("time")
1331-
dt_format = "%Y-%m-%dT%H:%M:%SZ"
1333+
try:
1334+
if is_step_function_event(event.get("detail")):
1335+
timestamp = event["detail"]["_datadog"]["State"]["EnteredTime"]
1336+
dt_format = "%Y-%m-%dT%H:%M:%S.%fZ"
1337+
except (TypeError, KeyError, AttributeError):
1338+
logger.debug("Error parsing timestamp from Step Functions event")
13321339

13331340
dt = datetime.strptime(timestamp, dt_format)
13341341

0 commit comments

Comments
 (0)