How to create independent subsegments in java?

Viewed 84

In our application, we are currently creating subsegments for our asynchronous downstream calls, but from looking at the AWS X-Ray documentation it seems that they are embedded with the parent segment that is created for the main thread.

Every once in awhile, we will get the error, where the main thread completes, therefor the entire segment (with embedded subsegments) is then sent to the xray daemon all at once, but one of the subsegments (asynchronous) completes after this main thread completion and throws an error in our logs because the parent segment is already sent the data to xray daemon and is completed.

We are wanting to to create the subsegments so that they are sent to the x-ray daemon independently, so if the main thread completes before any of the other threads (subsegments) it will not matter.

It seems that this is possible reviewing the AWS Xray documentation, but I can't find out how to implement this in java. I am having a really hard time finding examples and resources online other than the aws documentation below.

https://docs.aws.amazon.com/xray/latest/devguide/xray-api-sendingdata.html

1 Answers

You can find Java AWS X-Ray examples in the AWS Code Sample GitHUB repo. When looking for AWS Code examples in any of the supported languages, this is the best place to look.

You can find AWS X-Ray Java examples here:

https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/xray

These examples will get you up and running. To perform your use case, look at the JavaDocs for this service.

If you want an additional code example for this service, open an issue against the above Github repo.

Related