aws / aws/aws-xray-sdk-node

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

Open
#718 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
280
Forks
157
PR merge metrics
No merged PRs in 30d

Description

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!

Contributor guide

Open the contributing guide

Research direction

No file, test, or entry point is named. Start by locating the Lambda trace-context and sampling handling in the Node.js SDK, then check existing tests for Sampled=0 and Active tracing; done would be a documented or tested supported way to create a sampled trace, or a clear explanation that the behavior cannot be overridden.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript, node.js
Domain
backend, cloud, observability-sre
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.