Search in sources :

Example 6 with ContextPropagators

use of io.opentelemetry.context.propagation.ContextPropagators in project opentelemetry-java-instrumentation by open-telemetry.

the class PropagatorBasedSpanLinksExtractorTest method shouldExtractSpanLink.

@Test
void shouldExtractSpanLink() {
    // given
    ContextPropagators propagators = ContextPropagators.create(W3CTraceContextPropagator.getInstance());
    SpanLinksExtractor<Map<String, String>> underTest = SpanLinksExtractor.fromUpstreamRequest(propagators, new MapGetter());
    Map<String, String> request = singletonMap("traceparent", String.format("00-%s-%s-01", TRACE_ID, SPAN_ID));
    // when
    underTest.extract(spanLinks, Context.root(), request);
    // then
    verify(spanLinks).addLink(SpanContext.createFromRemoteParent(TRACE_ID, SPAN_ID, TraceFlags.getSampled(), TraceState.getDefault()));
}
Also used : ContextPropagators(io.opentelemetry.context.propagation.ContextPropagators) TextMapGetter(io.opentelemetry.context.propagation.TextMapGetter) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Test(org.junit.jupiter.api.Test)

Aggregations

ContextPropagators (io.opentelemetry.context.propagation.ContextPropagators)6 Test (org.junit.jupiter.api.Test)5 SdkTracerProvider (io.opentelemetry.sdk.trace.SdkTracerProvider)2 GlobalOpenTelemetry (io.opentelemetry.api.GlobalOpenTelemetry)1 OpenTelemetry (io.opentelemetry.api.OpenTelemetry)1 TextMapGetter (io.opentelemetry.context.propagation.TextMapGetter)1 TextMapPropagator (io.opentelemetry.context.propagation.TextMapPropagator)1 OpenTelemetrySdk (io.opentelemetry.sdk.OpenTelemetrySdk)1 OpenTelemetrySdkBuilder (io.opentelemetry.sdk.OpenTelemetrySdkBuilder)1 AutoConfigurationCustomizerProvider (io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider)1 ConfigProperties (io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties)1 SdkLogEmitterProvider (io.opentelemetry.sdk.logs.SdkLogEmitterProvider)1 SdkLogEmitterProviderBuilder (io.opentelemetry.sdk.logs.SdkLogEmitterProviderBuilder)1 SdkMeterProvider (io.opentelemetry.sdk.metrics.SdkMeterProvider)1 SdkMeterProviderBuilder (io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder)1 Resource (io.opentelemetry.sdk.resources.Resource)1 SdkTracerProviderBuilder (io.opentelemetry.sdk.trace.SdkTracerProviderBuilder)1 ArrayList (java.util.ArrayList)1 Collections.singletonMap (java.util.Collections.singletonMap)1 List (java.util.List)1