-
Notifications
You must be signed in to change notification settings - Fork 100
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
XRay multi threading - Failed to end subsegment: subsegment cannot be found #227
Comments
Hi @dan-lind, The X-Ray auto-instrumentation agent actually automatically propagates X-Ray context between threads, so you shouldn't need to do the |
Hi @willarmiros , I have actually tried that too, but it yields almost the same result, but instead the error is Will see if I can make a small reproducer or atleast get you the full stacktrace |
@willarmiros I've created a repro which should clearly display the issue I'm having. |
@dan-lind Thank you very much for the repro code, I will investigate this issue as soon as possible. |
Hi @dan-lind, I've figured out your problem after testing out your sample app. The problem in the So, the solution is to not rely on context within your async block. This is simple enough, changing the @GetMapping("/withIssue")
public ResponseEntity<?> withIssue() {
CompletableFuture.runAsync(() -> {
try {
Subsegment sub = AWSXRay.beginSubsegment("Sugsegment");
Thread.sleep(3000);
AWSXRay.getGlobalRecorder().endSubsegment(sub); // This method doesn't touch context storage
} catch (InterruptedException e) {
//NOOP
}
});
return ResponseEntity.ok().build();
} Since this is a pretty common use case that is particularly obscured by the magic of the agent, I'll do 2 things:
|
Thanks @willarmiros, I will test this! |
I have an issue using Xray in a multithreaded environment with my REST API. I'm using the Xray Auto instrumentation agent for Java, and Spring boot.
I've tried to follow the example found here https://docs.aws.amazon.com/xray/latest/devguide/scorekeep-workerthreads.html
However when ending my subsegment, I get a log output of "Suppressing AWS X-Ray context missing exception (SubsegmentNotFoundException): Failed to end subsegment: subsegment cannot be found."
I suspect what happens is that the request has been fully handled and response returned to the client, before the CompletableFuture is done. I assume this means that the Xray segment has been closed and that might explain why I'm seeing this issue. What I'm wondering is if there´s anything I can do to fix this?
I could probably live with this if it was only the trace within the CompletableFuture that was lost, but it looks like the entire trace is lost (there are calls to other HTTP services, dynamo DB etc, which won't show up unless I remove the piece of code below)
The text was updated successfully, but these errors were encountered: