aws / aws-xray-sdk-node

The official AWS X-Ray SDK for Node.js.
Apache License 2.0
266 stars 155 forks source link

Is there any way how to use XRay instrumentation for AWS NodeJS SDK v3? I have the below #639

Closed Sonumajuru closed 3 months ago

Sonumajuru commented 4 months ago

Hi I know issue might be closed but how can I trace using Xray for V3 client

const { captureAWSv3Client } = require('aws-xray-sdk-core') const { DynamoDBClient } = require('@aws-sdk/client-dynamodb') const { DynamoDBDocumentClient, GetCommand } = require('@aws-sdk/lib-dynamodb') then

const dynamodb = captureAWSv3Client(new DynamoDBClient(this.dynamoConfig)) this.docClient = DynamoDBDocumentClient.from(dynamodb) returns "error", "msg": "Missing AWS Lambda trace data for X-Ray. Ensure Active Tracing is enabled and no subsegments are created outside the function handler.",

There is no segments created out of this scope. Is Xray still not supported with V3?

jj22ee commented 3 months ago

Hi, are you trying to run a Lambda function locally? Lambda usually provides the Segment information to the user Lambda code, setting _X_AMZN_TRACE_ID env var. The X-Ray SDK will expect this segment/trace info from Lambda, otherwise can result in this type of error.

Can you confirm that this issues occurs when running this code locally, but will not appear when running in Lambda?

Sonumajuru commented 3 months ago

Hi, yes only happens when running locally, but found out that the issue was because of another aws service the getSignedUrl was tricky trying to mock it but it was the root cause of the issue of xray locally. Does not appear when running the Lambda.. I will close the issue, thanks