You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The default implementation of the aws-lambda instrumentation will only determine trace parent from http headers, but lambdas can be invoked through other mechanisms: sqs, event bridge, etc. It would be nice to make a basic attempt to determine trace parent for these other types.
Describe the solution you'd like
I would like the default context extractor method to perform further inspections on the event dictionary to determine if the trace parent can be obtained from other keys in the dictionary.
Describe alternatives you've considered
Currently I am parsing the event in a dummy handler and adding the sqs traceparent to event['headers'] to trick the instrumentation into assigning the correct parent. This solution works for a lambda event source batch size of 1, but doesn't make sense for larger than 1.
def handler(event, context):
records = event.get("Records")
if records:
event_source = records[0].get("EventSource") or records[0].get("eventSource")
if event_source == "aws:sqs":
# inject header information for sqs
traceparent = records[0].get("messageAttributes", {}).get('traceparent', {}).get('stringValue')
if traceparent:
headers = event.get("headers", {})
headers['traceparent'] = traceparent
event["headers"] = headers
return real_handler(event, context)
Additional Context
I don't think we have to solve for every scenario, but a better best effort would be appreciated. For example, if the event type is sqs and record size is 1, then attempt to pull the parent from message attributes. If the record size is larger than 1, then parentage can't be automatically determined and the end user should manually instrument parents of spans.
Would you like to implement a fix?
Yes
The text was updated successfully, but these errors were encountered:
What problem do you want to solve?
The default implementation of the aws-lambda instrumentation will only determine trace parent from http headers, but lambdas can be invoked through other mechanisms: sqs, event bridge, etc. It would be nice to make a basic attempt to determine trace parent for these other types.
Describe the solution you'd like
I would like the default context extractor method to perform further inspections on the event dictionary to determine if the trace parent can be obtained from other keys in the dictionary.
Describe alternatives you've considered
Currently I am parsing the event in a dummy handler and adding the sqs traceparent to event['headers'] to trick the instrumentation into assigning the correct parent. This solution works for a lambda event source batch size of 1, but doesn't make sense for larger than 1.
Additional Context
I don't think we have to solve for every scenario, but a better best effort would be appreciated. For example, if the event type is sqs and record size is 1, then attempt to pull the parent from message attributes. If the record size is larger than 1, then parentage can't be automatically determined and the end user should manually instrument parents of spans.
Would you like to implement a fix?
Yes
The text was updated successfully, but these errors were encountered: