Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The v2 version xray doesn't work for dynamodb putItem api #408

Open
zhaoyi0113 opened this issue Mar 3, 2023 · 3 comments
Open

The v2 version xray doesn't work for dynamodb putItem api #408

zhaoyi0113 opened this issue Mar 3, 2023 · 3 comments

Comments

@zhaoyi0113
Copy link

I am deploying code to Lambda and use below code to instrument dynamodb requests. It works fine for query but doesn't work for putItem.

awsv2.AWSV2Instrumentor(&cfg.APIOptions)
	// Using the Config value, create the DynamoDB client
	svc := dynamodb.NewFromConfig(cfg)

I got below error:

Suppressing AWS X-Ray context missing panic: failed to begin subsegment named 'DynamoDB': segment cannot be found.

Is there any other configuration needed for putItem?

@wangzlei
Copy link
Contributor

wangzlei commented Mar 13, 2023

This panic is xray sdk creates a subsegment but cannot find available parent segment from context, it happens in asynchronous case for example:

seg, ctx := xray.BeginSegment()
defer seg.Close()
go xray.BeginSubsegment(ctx)  // create subsegment after parent segment is closed.

So, probably your putItem method is running in async case but query is not.

Alternatively, user can use ADOT, it is xray's long term strategy to move from xray sdk to ADOT.
ADOT supports async in a better solution, would not have context missing panic. Please refer to a Lambda go example https://aws-otel.github.io/docs/getting-started/lambda/lambda-go

@zhaoyi0113
Copy link
Author

I am not running anything inside go routine, there should not be any async calls.
My application is running inside lambda and I thought the segment is created by lambda automatically. I don't need to call BeginSegment in my code for automatic tracing?

@wangzlei
Copy link
Contributor

In AWS Lambda scenario, X-Ray SDK will automatically find parent trace context from Lambda environment variable _X_AMZN_TRACE_ID, user no need call BeginSegment.
But it only works inside of user Lambda handler function. If user instruments his aws sdk and makes a call before Lambda handler function it will show segment cannot be found. error.

client = xray.instrument(client)
client.call()   // not support, Lambda does not env variable _X_AMZN_TRACE_ID yet

handler() { 
  client.call()  // support, because there is env variable _X_AMZN_TRACE_ID
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants