Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpret TraceParent from non-http lambda events #2764

Open
mlorenzana opened this issue Jul 31, 2024 · 0 comments · May be fixed by #2766
Open

Interpret TraceParent from non-http lambda events #2764

mlorenzana opened this issue Jul 31, 2024 · 0 comments · May be fixed by #2766

Comments

@mlorenzana
Copy link

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.

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

@mlorenzana mlorenzana linked a pull request Jul 31, 2024 that will close this issue
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant