aws / aws/aws-xray-sdk-node

Failed to get the current sub/segment from the context

Open
#415 10 comments 3 reactions 1 assignee Claimed by @srprash View on GitHub
question
Dominant language
JavaScript
Stars
280
Forks
157
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.