Segment Executor not running in background

Open
#347 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
aws, java, spring-boot

Research direction

Start by reproducing the /async-test endpoint with @Async and SegmentContextExecutors.newSegmentContextExecutor(), comparing it with CompletableFuture.supplyAsync without that executor. Trace why the request waits for three seconds and verify that the resolved behavior returns promptly while retaining segment logging.

Written by the indexing model from the issue text.

Description

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

Dominant language
Java
Stars
100
Forks
100
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from aws/aws-xray-sdk-java

All issues in aws/aws-xray-sdk-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.