Skip to content

How to force X-Ray tracing in a Lambda triggered by SQS with Sampled=0? #718

@guillaume-mindflow

Description

@guillaume-mindflow

Hi,

I'm working with a Lambda function that has X-Ray tracing set to Active. This Lambda is triggered by an SQS queue that does not have tracing enabled (and I want to keep it that way).

The problem I'm running into is: whenever a message comes from that SQS queue, it carries a trace header like this:

Root=1-686cfdde-7de1061135893bb36a649236;Parent=c1001c1cb4aab7cb;Sampled=0

And then in the Lambda logs I see:

DEBUG   Lambda trace data found: Root=1-686cfdde-7de1061135893bb36a649236;Parent=c1001c1cb4aab7cb;Sampled=0;Lineage=2:c3e4b99a:0
DEBUG   Ignoring flush on subsegment 996f50f237892ef1. Associated segment is marked as not sampled.

So effectively, no trace is sent, even though the Lambda is set to trace actively. It looks like the SDK respects the upstream Sampled=0 and removes all tracing behavior.

What I’m trying to do

I want the Lambda to always generate a trace, regardless of what’s in the incoming trace header. I understand that the trace context is passed from SQS, but since SQS tracing is off, the Sampled=0 is expected.
Still, I'd like my Lambda to override that and create a sampled trace anyway to trace sub-application.

My question

Is there a way to force the X-Ray SDK in Lambda to ignore Sampled=0 and start its own trace when tracing is set to Active?
Ideally, something like an environment variable or SDK setting that tells it to always sample regardless of the upstream trace context.
I've come across a few related discussions and GitHub issues, but I haven’t found a clear solution yet.

Thanks in advance for any clarification or suggestions!

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

    Issue actions