Skip to content

Conversation

@phipag
Copy link
Contributor

@phipag phipag commented Nov 19, 2025

Summary

This PR fixes an issue when using @Tracing together with parallel batch processing.

Before

When using parallel batch processing (without passing a custom Executor) we use a parallelStream() under the hood. A parallelStream() uses the common fork-join pool plus the main thread for processing. What happened was that some of sub-segments were not correctly attached to the parent ## handleRequest sub-segment. The reason is that X-RAY SDK maintains thread local trace entity instances. Hence, only the sub-sgements from the main thread and not those of the fork-join pool threads were correctly attached to the parent segment leading to a tracing output like this:

Screenshot 2025-11-18 at 15 12 28

After

This PR introduces propagation of the main thread's trace entity to the worker threads of the parallel batch processing worker threads. This fixes the issue such that all sub-segments are correctly attached to their parent segments. See screenshot after:

image (8)

Changes

Added XRayTraceEntityPropagator as a reflection wrapper around the X-RAY SDK methods needed for trace propagation following documentation at https://docs.aws.amazon.com/xray/latest/devguide/scorekeep-workerthreads.html.

The reason why we use reflection is because we should not take a dependency on the X-RAY SDK in the batch module. When X-RAY is not available, this will lead to a no-op.

We also update the documentation with better guidance on when to choose which concurrency model.

Note for reviewers: Created separate issue for addressing code duplication: #2302.

Issue number: #1671


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
20.8% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@phipag
Copy link
Contributor Author

phipag commented Nov 19, 2025

@humanzz Would love your opinion here (looking at your comment).

@phipag phipag marked this pull request as ready for review November 19, 2025 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant