|
20 | 20 | import io.opentelemetry.OpenTelemetry;
|
21 | 21 | import io.opentelemetry.common.AttributeKey;
|
22 | 22 | import io.opentelemetry.common.Attributes;
|
| 23 | +import io.opentelemetry.context.propagation.ContextPropagators; |
| 24 | +import io.opentelemetry.context.propagation.DefaultContextPropagators; |
23 | 25 | import io.opentelemetry.sdk.OpenTelemetrySdk;
|
24 | 26 | import io.opentelemetry.sdk.common.CompletableResultCode;
|
25 | 27 | import io.opentelemetry.sdk.trace.TracerSdkProvider;
|
26 | 28 | import io.opentelemetry.sdk.trace.data.SpanData;
|
27 | 29 | import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
|
28 | 30 | import io.opentelemetry.sdk.trace.export.SpanExporter;
|
29 | 31 | import io.opentelemetry.trace.StatusCanonicalCode;
|
| 32 | +import io.opentelemetry.trace.propagation.HttpTraceContext; |
30 | 33 | import org.junit.Test;
|
31 | 34 | import org.openqa.selenium.grid.web.CombinedHandler;
|
32 | 35 | import org.openqa.selenium.remote.http.HttpRequest;
|
@@ -85,6 +88,27 @@ public void shouldBeAbleToCreateATracer() {
|
85 | 88 |
|
86 | 89 | }
|
87 | 90 |
|
| 91 | + @Test |
| 92 | + public void shouldBeAbleToInjectContext() { |
| 93 | + List<SpanData> allSpans = new ArrayList<>(); |
| 94 | + Tracer tracer = createTracer(allSpans); |
| 95 | + |
| 96 | + HttpRequest cheeseReq = new HttpRequest(GET, "/cheeses"); |
| 97 | + |
| 98 | + assertThat(cheeseReq.getHeaderNames()).size().isEqualTo(0); |
| 99 | + |
| 100 | + try (Span span = tracer.getCurrentContext().createSpan("parent")) { |
| 101 | + span.setAttribute("cheese", "gouda"); |
| 102 | + span.setStatus(Status.NOT_FOUND); |
| 103 | + tracer.getPropagator().inject(tracer.getCurrentContext(), |
| 104 | + cheeseReq, |
| 105 | + (req, key, value) -> req.setHeader("cheese", "gouda")); |
| 106 | + } |
| 107 | + |
| 108 | + assertThat(cheeseReq.getHeaderNames()).size().isEqualTo(1); |
| 109 | + assertThat(cheeseReq.getHeaderNames()).element(0).isEqualTo("cheese"); |
| 110 | + } |
| 111 | + |
88 | 112 | @Test
|
89 | 113 | public void shouldBeAbleToCreateASpanWithAEvent() {
|
90 | 114 | List<SpanData> allSpans = new ArrayList<>();
|
@@ -568,8 +592,11 @@ public CompletableResultCode shutdown() {
|
568 | 592 | }).build());
|
569 | 593 |
|
570 | 594 | io.opentelemetry.trace.Tracer otTracer = provider.get("get");
|
| 595 | + ContextPropagators propagators = DefaultContextPropagators.builder() |
| 596 | + .addTextMapPropagator(HttpTraceContext.getInstance()).build(); |
| 597 | + |
571 | 598 | return new OpenTelemetryTracer(
|
572 | 599 | otTracer,
|
573 |
| - OpenTelemetry.getPropagators().getTextMapPropagator()); |
| 600 | + propagators.getTextMapPropagator()); |
574 | 601 | }
|
575 | 602 | }
|
0 commit comments