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

Segment Executor not running in background #347

Open
MostafaaRamadan opened this issue Jul 30, 2022 · 1 comment
Open

Segment Executor not running in background #347

MostafaaRamadan opened this issue Jul 30, 2022 · 1 comment

Comments

@MostafaaRamadan
Copy link

I have an api like this

   @GetMapping("/async-test")
    public String api2() throws InterruptedException {
        log.info("Before async");
        myService.myAsync();
        log.info("after async");
        return "nothing important";
    }

And myService.myAsync implementation like this

@Async
    public void myAsync() {
        CompletableFuture.supplyAsync(() -> {
            try {
                log.info("before thread ....");
                Thread.sleep(3000);
                log.info("after thread ....");
            } catch (InterruptedException e) {
                throw new IllegalStateException(e);
            }
            log.info("before returning result ....");
            return "Result of the asynchronous computation";
        }, SegmentContextExecutors.newSegmentContextExecutor());
    }

The issue here is that API waits for 3 seconds to reply when using SegmentContextExecutors.newSegmentContextExecutor(), but if I remove the segment executor, the function run in the background successfully, but for sure I lose the segment logging.

So what should be done to fix this ?
Tech stack
Spring boot v.2.7.2
Java 11
Aws x-ray v.2.11.2

@wangzlei
Copy link
Contributor

Hi,

XRay SDK does not support asyn scenario very well because Segment(Subsegment) and SegmentContext are not decoupled. So XRay SDK can handle async case child subsegment gets closed early than parent Segment, but is hard to handle async case child subsegment starts later than parent, or close later than parent.
Sorry that we know this issue for a long time but have no bandwidth working on it. Alternatively we recommend user move on to opentelemetry, it automatically covers async scenario in context.

Please refer to ADOT doc.

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