Skip to content

Preserving trace id in Lambda -> SQS -> Lambda flow #59

@triha74

Description

@triha74

Runtime:
All of them

Is your feature request related to a problem? Please describe
SQS Supports XRay but since Lambda execution is done as batch the lambda function consuming the queue starts a new trace. To work around this the consuming lambda needs to over write the traceid with the AWSTraceHeader value.

`func handler(ctx context.Context, event events.SQSEvent) {

if trcHdrStr, ok := event.Records[0].Attributes["AWSTraceHeader"]; ok {
	traceHeader := header.FromString(trcHdrStr)

	var seg *xray.Segment
	ctx, seg = xray.BeginSegment(ctx, "YOUR-SEGMENT-NAME")
	seg.TraceID = traceHeader.TraceID
	seg.ParentID = traceHeader.ParentID
	seg.Sampled = traceHeader.SamplingDecision == header.Sampled

	defer seg.Close(nil)
}

}`

This is described at length here https://medium.com/@filiplubniewski/distributed-tracing-in-serverless-with-x-ray-lambda-sqs-and-golang-f38616cbd79b

Describe the solution you'd like
This would be perfect to have as an annotation

Describe alternatives you've considered
Its obivously an annotation ;)

If you provide guidance, is this something you'd like to contribute?

Additional context

Activity

dreamorosi

dreamorosi commented on Jul 17, 2025

@dreamorosi
Contributor

We haven't received any significant traction on this item in the past 4 years, because of this we'll close it as not planned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @triha74@dreamorosi

        Issue actions

          Preserving trace id in Lambda -> SQS -> Lambda flow · Issue #59 · aws-powertools/powertools-lambda