Search in sources :

Example 6 with SdkTracerProvider

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);
}
Also used : SdkMeterProvider(io.opentelemetry.sdk.metrics.SdkMeterProvider) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider)

Example 7 with SdkTracerProvider

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 : .*"));
    });
}
Also used : Tracer(io.opentelemetry.api.trace.Tracer) ArrayList(java.util.ArrayList) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider) Test(org.junit.jupiter.api.Test)

Example 8 with SdkTracerProvider

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();
}
Also used : Tracer(io.opentelemetry.api.trace.Tracer) WeakReference(java.lang.ref.WeakReference) ArrayList(java.util.ArrayList) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider) Span(io.opentelemetry.api.trace.Span) Test(org.junit.jupiter.api.Test)

Example 9 with SdkTracerProvider

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;
}
Also used : Resource(io.opentelemetry.sdk.resources.Resource) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider) OtlpGrpcSpanExporter(io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter) BatchSpanProcessor(io.opentelemetry.sdk.trace.export.BatchSpanProcessor)

Example 10 with SdkTracerProvider

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);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Sampler(io.opentelemetry.sdk.trace.samplers.Sampler) BeforeEach(org.junit.jupiter.api.BeforeEach) LogProcessor(io.opentelemetry.sdk.logs.LogProcessor) SpanId(io.opentelemetry.api.trace.SpanId) W3CTraceContextPropagator(io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator) OpenTelemetrySdk(io.opentelemetry.sdk.OpenTelemetrySdk) Resource(io.opentelemetry.sdk.resources.Resource) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) TextMapPropagator(io.opentelemetry.context.propagation.TextMapPropagator) MetricReader(io.opentelemetry.sdk.metrics.export.MetricReader) SimpleSpanProcessor(io.opentelemetry.sdk.trace.export.SimpleSpanProcessor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) ContextKey(io.opentelemetry.context.ContextKey) Context(io.opentelemetry.context.Context) IdGenerator(io.opentelemetry.sdk.trace.IdGenerator) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Span(io.opentelemetry.api.trace.Span) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) OpenTelemetry(io.opentelemetry.api.OpenTelemetry) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) Mockito.when(org.mockito.Mockito.when) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider) Mockito.verify(org.mockito.Mockito.verify) GlobalOpenTelemetry(io.opentelemetry.api.GlobalOpenTelemetry) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) SdkMeterProvider(io.opentelemetry.sdk.metrics.SdkMeterProvider) Mockito(org.mockito.Mockito) List(java.util.List) InMemorySpanExporter(io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter) AttributeKey.stringKey(io.opentelemetry.api.common.AttributeKey.stringKey) TextMapGetter(io.opentelemetry.context.propagation.TextMapGetter) MetricReaderFactory(io.opentelemetry.sdk.metrics.export.MetricReaderFactory) TraceId(io.opentelemetry.api.trace.TraceId) SpanData(io.opentelemetry.sdk.trace.data.SpanData) Collections(java.util.Collections) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider) Test(org.junit.jupiter.api.Test)

Aggregations

SdkTracerProvider (io.opentelemetry.sdk.trace.SdkTracerProvider)39 Test (org.junit.jupiter.api.Test)20 ReadableSpan (io.opentelemetry.sdk.trace.ReadableSpan)9 Resource (io.opentelemetry.sdk.resources.Resource)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 SpanBuilder (io.opentelemetry.api.trace.SpanBuilder)7 MavenGoal (io.opentelemetry.maven.MavenGoal)7 OpenTelemetrySdk (io.opentelemetry.sdk.OpenTelemetrySdk)7 ExecutionEvent (org.apache.maven.execution.ExecutionEvent)7 MavenProject (org.apache.maven.project.MavenProject)7 Span (io.opentelemetry.api.trace.Span)6 Tracer (io.opentelemetry.api.trace.Tracer)6 SpanData (io.opentelemetry.sdk.trace.data.SpanData)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)5 GlobalOpenTelemetry (io.opentelemetry.api.GlobalOpenTelemetry)4 OpenTelemetry (io.opentelemetry.api.OpenTelemetry)4 SdkLogEmitterProvider (io.opentelemetry.sdk.logs.SdkLogEmitterProvider)4 SdkMeterProvider (io.opentelemetry.sdk.metrics.SdkMeterProvider)4