use of io.opentelemetry.sdk.trace.SdkTracerProvider in project opentelemetry-java by open-telemetry.
the class OpenTelemetrySdkBuilder method build.
/**
* Returns a new {@link OpenTelemetrySdk} built with the configuration of this {@link
* OpenTelemetrySdkBuilder}. This SDK is not registered as the global {@link
* io.opentelemetry.api.OpenTelemetry}. It is recommended that you register one SDK using {@link
* OpenTelemetrySdkBuilder#buildAndRegisterGlobal()} for use by instrumentation that requires
* access to a global instance of {@link io.opentelemetry.api.OpenTelemetry}.
*
* @see GlobalOpenTelemetry
*/
public OpenTelemetrySdk build() {
SdkTracerProvider tracerProvider = this.tracerProvider;
if (tracerProvider == null) {
tracerProvider = SdkTracerProvider.builder().build();
}
SdkMeterProvider meterProvider = this.meterProvider;
if (meterProvider == null) {
meterProvider = SdkMeterProvider.builder().build();
}
SdkLogEmitterProvider logEmitterProvider = this.logEmitterProvider;
if (logEmitterProvider == null) {
logEmitterProvider = SdkLogEmitterProvider.builder().build();
}
return new OpenTelemetrySdk(tracerProvider, meterProvider, logEmitterProvider, propagators);
}
use of io.opentelemetry.sdk.trace.SdkTracerProvider in project opentelemetry-java by open-telemetry.
the class LeakDetectingSpanProcessorTest method garbageCollectedUnendedSpan.
@Test
void garbageCollectedUnendedSpan() {
List<Throwable> logs = new ArrayList<>();
LeakDetectingSpanProcessor spanProcessor = new LeakDetectingSpanProcessor((message, callerStackTrace) -> logs.add(callerStackTrace));
SdkTracerProvider tracerProvider = SdkTracerProvider.builder().addSpanProcessor(spanProcessor).build();
Tracer tracer = tracerProvider.get("test");
tracer.spanBuilder("testSpan").startSpan();
await().atMost(Duration.ofSeconds(30)).untilAsserted(() -> {
System.gc();
assertThat(logs).singleElement().satisfies(callerStackTrace -> assertThat(callerStackTrace.getMessage()).matches("Span garbage collected before being ended\\. " + "Thread: \\[.*\\] started span : .*"));
});
}
use of io.opentelemetry.sdk.trace.SdkTracerProvider in project opentelemetry-java by open-telemetry.
the class LeakDetectingSpanProcessorTest method garbageCollectedEndedSpan.
@Test
void garbageCollectedEndedSpan() {
List<Throwable> logs = new ArrayList<>();
LeakDetectingSpanProcessor spanProcessor = new LeakDetectingSpanProcessor((message, callerStackTrace) -> logs.add(callerStackTrace));
SdkTracerProvider tracerProvider = SdkTracerProvider.builder().addSpanProcessor(spanProcessor).build();
Tracer tracer = tracerProvider.get("test");
Span testSpan = tracer.spanBuilder("testSpan").startSpan();
WeakReference<Span> spanRef = new WeakReference<>(testSpan);
testSpan.end();
testSpan = null;
GcFinalization.awaitClear(spanRef);
assertThat(logs).isEmpty();
}
use of io.opentelemetry.sdk.trace.SdkTracerProvider in project opentelemetry-java by open-telemetry.
the class OtlpPipelineStressTest method setupSdk.
private void setupSdk() {
Resource resource = Resource.create(Attributes.builder().put(ResourceAttributes.SERVICE_NAME, "PerfTester").put(ResourceAttributes.SERVICE_VERSION, "1.0.1-RC-1").build());
// set up the metric exporter and wire it into the SDK and a timed reader.
meterProvider = SdkMeterProvider.builder().setResource(resource).registerMetricReader(PeriodicMetricReader.builder(metricExporter).setInterval(Duration.ofSeconds(1)).newMetricReaderFactory()).build();
// set up the span exporter and wire it into the SDK
OtlpGrpcSpanExporter spanExporter = OtlpGrpcSpanExporter.builder().setMeterProvider(meterProvider).setEndpoint("http://" + toxiproxyContainer.getHost() + ":" + toxiproxyContainer.getMappedPort(COLLECTOR_PROXY_PORT)).build();
BatchSpanProcessor spanProcessor = BatchSpanProcessor.builder(spanExporter).setMeterProvider(meterProvider).build();
SdkTracerProvider tracerProvider = SdkTracerProvider.builder().addSpanProcessor(spanProcessor).build();
openTelemetry = OpenTelemetrySdk.builder().setTracerProvider(tracerProvider).buildAndRegisterGlobal();
sdkTracerProvider = tracerProvider;
}
use of io.opentelemetry.sdk.trace.SdkTracerProvider in project opentelemetry-java by open-telemetry.
the class AutoConfiguredOpenTelemetrySdkTest method builder_addSpanExporterCustomizer.
@Test
void builder_addSpanExporterCustomizer() {
Mockito.lenient().when(spanExporter2.shutdown()).thenReturn(CompletableResultCode.ofSuccess());
SdkTracerProvider sdkTracerProvider = builder.addSpanExporterCustomizer((previous, config) -> {
assertThat(previous).isSameAs(SpanExporter.composite());
return spanExporter1;
}).addSpanExporterCustomizer((previous, config) -> {
assertThat(previous).isSameAs(spanExporter1);
return spanExporter2;
}).build().getOpenTelemetrySdk().getSdkTracerProvider();
assertThat(sdkTracerProvider).extracting("sharedState").extracting("activeSpanProcessor").extracting("worker").extracting("spanExporter").isEqualTo(spanExporter2);
}
Aggregations