Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mlorenzana authored and Michael Lorenzana committed Dec 4, 2024
1 parent e12fa02 commit 68b95d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ def _default_event_context_extractor(lambda_event: Any) -> Context:

records = lambda_event.get("Records")
if records and isinstance(records, list) and len(records) == 1:
message_attributes = records[0]['messageAttributes']
message_attributes = records[0]["messageAttributes"]
if message_attributes and isinstance(message_attributes, dict):
return get_global_textmap().extract(message_attributes, getter=LambdaSqsGetter())
return get_global_textmap().extract(
message_attributes, getter=LambdaSqsGetter()
)
except (TypeError, KeyError, AttributeError):
logger.debug(
"Extracting context from Lambda Event failed: either enable X-Ray active tracing or configure API Gateway to trigger this Lambda function as a pure proxy. Otherwise, generated spans will have an invalid (empty) parent context."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,22 @@ def custom_event_context_extractor(lambda_event):
custom_extractor=None,
context={
"Records": [
{'messageAttributes': {
TraceContextTextMapPropagator._TRACEPARENT_HEADER_NAME: {
'stringValue': MOCK_W3C_TRACE_CONTEXT_SAMPLED, 'stringListValues': [],
'binaryListValues': [], 'dataType': 'String'}
}}
{
"messageAttributes": {
TraceContextTextMapPropagator._TRACEPARENT_HEADER_NAME: {
"stringValue": MOCK_W3C_TRACE_CONTEXT_SAMPLED,
"stringListValues": [],
"binaryListValues": [],
"dataType": "String",
}
}
}
]
},
expected_traceid=MOCK_W3C_TRACE_ID,
expected_parentid=MOCK_W3C_PARENT_SPAN_ID,
xray_traceid=MOCK_XRAY_TRACE_CONTEXT_SAMPLED,
),
expected_traceid=MOCK_W3C_TRACE_ID,
expected_parentid=MOCK_W3C_PARENT_SPAN_ID,
xray_traceid=MOCK_XRAY_TRACE_CONTEXT_SAMPLED,
),
]
for test in tests:
with self.subTest(test_name=test.name):
Expand Down

0 comments on commit 68b95d5

Please sign in to comment.