use of io.opentelemetry.context.propagation.ContextPropagators in project opentelemetry-java by open-telemetry.
the class OpenTelemetryTest method independentNonGlobalPropagators.
@Test
void independentNonGlobalPropagators() {
ContextPropagators propagators1 = mock(ContextPropagators.class);
OpenTelemetry otel1 = OpenTelemetry.propagating(propagators1);
ContextPropagators propagators2 = mock(ContextPropagators.class);
OpenTelemetry otel2 = OpenTelemetry.propagating(propagators2);
assertThat(otel1.getPropagators()).isSameAs(propagators1);
assertThat(otel2.getPropagators()).isSameAs(propagators2);
}
use of io.opentelemetry.context.propagation.ContextPropagators in project opentelemetry-java by open-telemetry.
the class OpenTracingShimTest method createTracerShim_fromOpenTelemetryInstance.
@Test
void createTracerShim_fromOpenTelemetryInstance() {
OpenTelemetry openTelemetry = mock(OpenTelemetry.class);
SdkTracerProvider sdk = SdkTracerProvider.builder().build();
when(openTelemetry.getTracerProvider()).thenReturn(sdk);
ContextPropagators contextPropagators = mock(ContextPropagators.class);
when(contextPropagators.getTextMapPropagator()).thenReturn(mock(TextMapPropagator.class));
when(openTelemetry.getPropagators()).thenReturn(contextPropagators);
TracerShim tracerShim = (TracerShim) OpenTracingShim.createTracerShim(openTelemetry);
assertThat(tracerShim.tracer()).isEqualTo(sdk.get("opentracingshim"));
}
use of io.opentelemetry.context.propagation.ContextPropagators in project opentelemetry-java by open-telemetry.
the class AutoConfiguredOpenTelemetrySdkBuilder method build.
/**
* Returns a new {@link AutoConfiguredOpenTelemetrySdk} holding components auto-configured using
* the settings of this {@link AutoConfiguredOpenTelemetrySdkBuilder}.
*/
public AutoConfiguredOpenTelemetrySdk build() {
if (!customized) {
customized = true;
mergeSdkTracerProviderConfigurer();
for (AutoConfigurationCustomizerProvider customizer : ServiceLoader.load(AutoConfigurationCustomizerProvider.class, serviceClassLoader)) {
customizer.customize(this);
}
}
ConfigProperties config = getConfig();
Resource resource = ResourceConfiguration.configureResource(config, serviceClassLoader, resourceCustomizer);
SdkMeterProviderBuilder meterProviderBuilder = SdkMeterProvider.builder();
meterProviderBuilder.setResource(resource);
MeterProviderConfiguration.configureMeterProvider(meterProviderBuilder, config, serviceClassLoader, metricExporterCustomizer);
meterProviderBuilder = meterProviderCustomizer.apply(meterProviderBuilder, config);
SdkMeterProvider meterProvider = meterProviderBuilder.build();
SdkTracerProviderBuilder tracerProviderBuilder = SdkTracerProvider.builder();
tracerProviderBuilder.setResource(resource);
TracerProviderConfiguration.configureTracerProvider(tracerProviderBuilder, config, serviceClassLoader, meterProvider, spanExporterCustomizer, samplerCustomizer);
tracerProviderBuilder = tracerProviderCustomizer.apply(tracerProviderBuilder, config);
SdkTracerProvider tracerProvider = tracerProviderBuilder.build();
SdkLogEmitterProviderBuilder logEmitterProviderBuilder = SdkLogEmitterProvider.builder();
logEmitterProviderBuilder.setResource(resource);
LogEmitterProviderConfiguration.configureLogEmitterProvider(logEmitterProviderBuilder, config, meterProvider, logExporterCustomizer);
logEmitterProviderBuilder = logEmitterProviderCustomizer.apply(logEmitterProviderBuilder, config);
SdkLogEmitterProvider logEmitterProvider = logEmitterProviderBuilder.build();
if (registerShutdownHook) {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
List<CompletableResultCode> shutdown = new ArrayList<>();
shutdown.add(tracerProvider.shutdown());
shutdown.add(meterProvider.shutdown());
shutdown.add(logEmitterProvider.shutdown());
CompletableResultCode.ofAll(shutdown).join(10, TimeUnit.SECONDS);
}));
}
ContextPropagators propagators = PropagatorConfiguration.configurePropagators(config, serviceClassLoader, propagatorCustomizer);
OpenTelemetrySdkBuilder sdkBuilder = OpenTelemetrySdk.builder().setTracerProvider(tracerProvider).setLogEmitterProvider(logEmitterProvider).setMeterProvider(meterProvider).setPropagators(propagators);
OpenTelemetrySdk openTelemetrySdk = sdkBuilder.build();
if (setResultAsGlobal) {
GlobalOpenTelemetry.set(openTelemetrySdk);
logger.log(Level.FINE, "Global OpenTelemetrySdk set to {0} by autoconfiguration", openTelemetrySdk);
}
return AutoConfiguredOpenTelemetrySdk.create(openTelemetrySdk, resource, config);
}
use of io.opentelemetry.context.propagation.ContextPropagators in project opentelemetry-java by open-telemetry.
the class PropagatorConfigurationTest method defaultPropagators.
@Test
void defaultPropagators() {
ContextPropagators contextPropagators = PropagatorConfiguration.configurePropagators(DefaultConfigProperties.createForTest(Collections.emptyMap()), PropagatorConfiguration.class.getClassLoader(), (a, unused) -> a);
assertThat(contextPropagators.getTextMapPropagator().fields()).containsExactlyInAnyOrder("traceparent", "tracestate", "baggage");
}
use of io.opentelemetry.context.propagation.ContextPropagators in project opentelemetry-java by open-telemetry.
the class OpenTelemetryTest method propagating.
@Test
void propagating() {
ContextPropagators contextPropagators = mock(ContextPropagators.class);
OpenTelemetry openTelemetry = OpenTelemetry.propagating(contextPropagators);
assertThat(openTelemetry.getTracerProvider()).isSameAs(TracerProvider.noop());
assertThat(openTelemetry.getMeterProvider()).isSameAs(MeterProvider.noop());
assertThat(openTelemetry.getPropagators()).isSameAs(contextPropagators);
}
Aggregations