Comments (8)
Hi Scandinaro,
We have an open issue with Dynamo Document Client here:
#23
Could you verify the work-around fixes your context propagation issue?
Thanks,
Sandra
from aws-xray-sdk-node.
@awssandra above I'm using one example from that linked issue solution, and then below I just tried the last suggested solution from @monken, but I'm still receiving the same error. It seems like maybe this solution works for express, but not restify?
const AWS = require('./aws');
const AWSXray = require('aws-xray-sdk');
const dynamoOptions = {
httpOptions: {
timeout: 2000
},
maxRetries: 0
};
const dynamoDb = new AWS.DynamoDB.DocumentClient({
service: new AWS.DynamoDB(dynamoOptions)
});
AWSXray.captureAWSClient(dynamoDb.service);
from aws-xray-sdk-node.
That should not be the case. The SDK uses CLS behind the scenes to propagate context, regardless of the framework in use. The context is either getting lost as a part of the Restify hook, or in the AWS call.
Do any other AWS calls work?
Can you verify if a "xray.getSegment()" call in the route returns the base segment?
What version of Restify are you using?
Is the "xray.enable(/server/, /name/)" call immediately before your defined routes (after any/all interceptors/hooks)?
from aws-xray-sdk-node.
Do any other AWS calls work?
Yes, we are individually using capture aws client on the cognito client successfully. Dynamo is the only aws service we are using which is having this issue obviously at least somewhat related to using the document client vs the core dynamo module. this is less relevant because of a below answer
Can you verify if a "xray.getSegment()" call in the route returns the base segment?
I was able to confirm that calling it in the route before doing anything else, results in an unhandled promise rejection thrown Error: Failed to get the current sub/segment from the context.
this is less relevant because of a below answer
What version of Restify are you using?
We are running 4.1.1 in production, but I just tried upgrading to 7.3.0 but we are still throwing the same error for both trying to call xray.getSegment() as well as when trying to use capture client on the dynamo module. Since I just went through the trouble of replacing all our restify middleware with the 5.0+ compatible styles we will now be running 7.3 in production shortly. this is less relevant because of a below answer
Is the "xray.enable(/server/, /name/)" call immediately before your defined routes (after any/all interceptors/hooks)?
This seems to be the source of some of our issues. We use the aws cognito module in our authentication middleware to authenticate API requests for some routes. Removing the xray client wrapper from cognito and moving the xray enable command after our last middleware seems to fix the dynamo segment error that we were getting on all requests with subsequent dynamo db calls, but now it seems that while we always have access to the xray segment in the route, it only makes it to the dynamo module on some requests and not others. It seems like it might somehow be related to the HTTP Method? It seems like it might work on GETs but not POST and DELETE? In one example, on a DELETE HTTP request we actually have back to back dynamodb calls. The first call is a dynamob.get() request which doesn't throw the sub/segment error, then the second request fired syncronously after the first is a dynamodb.put request which does throw the error.
from aws-xray-sdk-node.
@awssandra just following back up on this.
from aws-xray-sdk-node.
Hi scandinaro,
Apologies for the delay, much of the team was out for vacation (myself included) and recently back. We're diving into this and will update you as soon as we have more information.
Thanks,
Sandra
from aws-xray-sdk-node.
@scandinaro
I'm trying to reproduce the issue you're seeing but haven't had much luck yet. Here's my full code based on the original example you provided:
dynamodb.js
const AWS = require('aws-sdk');
const xray = require('aws-xray-sdk');
const options = {
httpOptions: {
timeout: 2000
},
maxRetries: 0,
region: 'us-west-2'
};
const client = xray.captureAWSClient(new AWS.DynamoDB(options));
const docClient = new AWS.DynamoDB.DocumentClient(options);
docClient.service = client;
module.exports = {
client: docClient
};
app.js
const resitfy = require('restify');
const xray = require('aws-xray-sdk-restify');
const client = require('./dynamodb').client;
function createServer() {
const server = resitfy.createServer({
name: 'api'
});
xray.enable(server, 'restify-root');
server.use(resitfy.plugins.dateParser());
server.use(resitfy.plugins.queryParser());
server.use(resitfy.plugins.bodyParser());
server.get('/foo', function(req, res, next) {
client.scan({
TableName: 'TABLE'
}, function(err, data) {
if (err) {
res.send(err.statusCode, err.message);
next(err);
} else {
res.send(200, data);
next();
}
});
});
server.get('/bar', function(req, res, next) {
client.get({
TableName: 'TABLE',
Key: {
'id': 'ID'
}
}, function(err, data) {
if (err) {
res.send(err.statusCode, err.message);
next(err);
} else {
data.Item.timestamp = Date.now();
client.put({
TableName: 'TABLE',
Item: data.Item,
ReturnValues: 'ALL_OLD'
}, function(err, data) {
if (err) {
res.send(err.statusCode, err.message);
next(err);
} else {
res.send(200, data);
next();
}
});
}
});
});
return server;
}
const server = createServer();
server.listen(3002);
Where do you attach your auth middleware? And are you using promises in your routes/middleware? I tried making the GET /bar
route match your last use case where you get an item, then put an item as a result. Let me know if what you have differs from what I've put together.
from aws-xray-sdk-node.
Closing due to inactivity, but feel free to open a new issue if you are still encountering this error.
from aws-xray-sdk-node.
Related Issues (20)
- Size of the aws-xray-sdk-core package dependencies (i.e. the bundle) HOT 1
- memory leaks caused by cls-hooked HOT 3
- Vulnerability in the library HOT 6
- Adding custom attributes to AWS SDK v3 calls HOT 2
- Please update readme for postgres
- captureAWSv3Client doesn't support SecretManager client HOT 3
- Add support for the lamda-api web framework
- captureAsyncFunc is not working for AWS Lambda with runtime nodejs 16 HOT 1
- Release 3.5.2 HOT 2
- Segment containing BigInt in metadata throws an error when serialized HOT 2
- Cannot find module 'aws-xray-sdk' in nodejs Lambda
- warning message @aws-sdk/service-error-classification is moved to @smithy/service-error-classification
- Support undici HOT 1
- Consider supporting SQL annotations for Athena calls. HOT 1
- Feature Request | ServiceMap in X-Ray Tracing does not show EventBridge and SQS
- Creating Linked Traces between SQS Producer and Consumer on Non Serverless Compute HOT 2
- Is there any way how to use XRay instrumentation for AWS NodeJS SDK v3? I have the below HOT 2
- SimulatePrincipalpolicy:: Python SDK does not work with regular expressions HOT 1
- Wrong link to the sdk contrib readmes HOT 1
- fetch with URL object fails with `Cannot read properties of undefined (reading 'has')`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-xray-sdk-node.