|
43 | 43 | import io.opentelemetry.api.trace.Span; |
44 | 44 | import io.opentelemetry.api.trace.SpanKind; |
45 | 45 | import io.opentelemetry.context.Context; |
| 46 | +import io.opentelemetry.context.Scope; |
46 | 47 | import io.opentelemetry.context.propagation.TextMapPropagator; |
47 | 48 | import io.opentelemetry.context.propagation.TextMapSetter; |
48 | 49 | import io.opentelemetry.instrumentation.test.utils.PortUtils; |
@@ -175,16 +176,21 @@ void highConcurrency() throws Exception { |
175 | 176 | Thread.currentThread().interrupt(); |
176 | 177 | throw new AssertionError(e); |
177 | 178 | } |
178 | | - testing.runWithSpan( |
179 | | - "client " + index, |
180 | | - () -> { |
181 | | - HttpRequestBuilder builder = |
182 | | - HttpRequest.builder() |
183 | | - .get(baseUrl + "?" + TEST_REQUEST_ID_PARAMETER + "=" + index); |
184 | | - Span.current().setAttribute(TEST_REQUEST_ID_ATTRIBUTE, index); |
185 | | - propagator.inject(Context.current(), builder, setter); |
186 | | - client.execute(builder.build()).aggregate().join(); |
187 | | - }); |
| 179 | + // run under Context.root() so each client request starts a fresh trace, |
| 180 | + // regardless of any thread-local context leftover from a previous task on |
| 181 | + // the same pool worker |
| 182 | + try (Scope ignored = Context.root().makeCurrent()) { |
| 183 | + testing.runWithSpan( |
| 184 | + "client " + index, |
| 185 | + () -> { |
| 186 | + HttpRequestBuilder builder = |
| 187 | + HttpRequest.builder() |
| 188 | + .get(baseUrl + "?" + TEST_REQUEST_ID_PARAMETER + "=" + index); |
| 189 | + Span.current().setAttribute(TEST_REQUEST_ID_ATTRIBUTE, index); |
| 190 | + propagator.inject(Context.current(), builder, setter); |
| 191 | + client.execute(builder.build()).aggregate().join(); |
| 192 | + }); |
| 193 | + } |
188 | 194 | })); |
189 | 195 | } |
190 | 196 |
|
|
0 commit comments