Failed to get the current sub/segment from the context

See original GitHub issue

I have a NodeJs service (using express) that we are now trying to monitor with Xray. For some reason, every time a new request is issued, I get the following error:

[ERROR] Error: Failed to get the current sub/segment from the context.
    at Object.contextMissingLogError [as contextMissing] (/Users/ronagar/src/node_modules/aws-xray-sdk-core/lib/context_utils.js:26:19)
    at Object.getSegment (/Users/ronagar/src/node_modules/aws-xray-sdk-core/lib/context_utils.js:102:45)
    at tryGetCurrentSegment (/Users/ronagar/src/node_modules/aws-xray-sdk-core/lib/patchers/promise_p.js:63:25)
    at Promise.then (/Users/ronagar/src/node_modules/aws-xray-sdk-core/lib/patchers/promise_p.js:20:12)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

There’s no additional stack, so there’s really no way to determine where this issue comes from. After hours of debugging I’m still clueless as to where the culprit is. Every time I change something, the error pops up some place else. As you can see the error happens in the promise patching. when disabling capturePromise the error goes away, but we need this as we have many promises & external calls running during the request. One thing that I keep noticing is that if I see the error happens when calling a specific function. I change this function code to async/await and suddenly this goes away. but I do have other functions that do have regular promises and they don’t crash. Is there any way to identify what is the culprit? how to resolve this?

Stack that I think relevant: NodeJs 12.17.0 aws-sdk 2.294.0 aws-xray-sdk 3.3.1 axios 0.21.2 bluebird 3.7.2

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
willarmiroscommented, May 10, 2021

@atlanteh if you don’t want this error to come up while debugging please set the AWS_XRAY_CONTEXT_MISSING environment variable to LOG_ERROR or IGNORE_ERROR. For more info, see the readme.

1reaction
stale[bot]commented, Jan 8, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs in next 7 days. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error:"Failed to get the current sub/segment from ...
One possible way to pass this error and still be able to call your function locally is setting AWS_XRAY_CONTEXT_MISSING environment variable to ...
Read more >
Troubleshooting AWS X-Ray
SegmentNotFoundException: Failed to begin subsegment named 'AmazonSNS': segment cannot be found. This error indicates that the X-Ray SDK attempted to record an ...
Read more >
Tracer | aws-lambda-powertools-typescript
Add an error to the current segment or subsegment as metadata. ... https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html ...
Read more >
aws-xray-sdk-core
You can retrieve the current segment or subsegment at any time using the ... context but cannot find one, it throws a runtime...
Read more >
Troubleshooting Amazon X-Ray
SegmentNotFoundException: Failed to begin subsegment named 'AmazonSNS': ... methods to get a reference to the current segment or subsegment ( Entity ) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found