use of io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter in project opentelemetry-java by open-telemetry.
the class AutoConfiguredOpenTelemetrySdkTest method tracerProviderCustomizer.
@Test
void tracerProviderCustomizer() {
InMemorySpanExporter spanExporter = InMemorySpanExporter.create();
AutoConfiguredOpenTelemetrySdkBuilder autoConfiguration = AutoConfiguredOpenTelemetrySdk.builder().addTracerProviderCustomizer((tracerProviderBuilder, config) -> {
tracerProviderBuilder.setResource(Resource.builder().put("cat", "meow").build());
return tracerProviderBuilder.addSpanProcessor(SimpleSpanProcessor.create(spanExporter));
}).addResourceCustomizer((resource, config) -> resource.merge(Resource.builder().put("cow", "moo").build())).addPropertiesSupplier(() -> Collections.singletonMap("otel.metrics.exporter", "none")).addPropertiesSupplier(() -> Collections.singletonMap("otel.traces.exporter", "none")).addPropertiesSupplier(() -> Collections.singletonMap("otel.logs.exporter", "none")).setResultAsGlobal(false);
GlobalOpenTelemetry.set(OpenTelemetry.noop());
AutoConfiguredOpenTelemetrySdk autoConfigured = autoConfiguration.build();
assertThat(autoConfigured.getResource().getAttribute(stringKey("cow"))).isEqualTo("moo");
OpenTelemetrySdk sdk = autoConfigured.getOpenTelemetrySdk();
sdk.getTracerProvider().get("test").spanBuilder("test").startSpan().end();
List<SpanData> spanItems = spanExporter.getFinishedSpanItems();
assertThat(spanItems.size()).isEqualTo(1);
SpanData spanData = spanItems.get(0);
assertThat(spanData.getResource().getAttribute(stringKey("cat"))).isEqualTo("meow");
// Ensures the export happened.
sdk.getSdkTracerProvider().shutdown().join(10, TimeUnit.SECONDS);
}
use of io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter in project opentelemetry-java by open-telemetry.
the class OpenTelemetryRule method create.
/**
* Returns a {@link OpenTelemetryRule} with a default SDK initialized with an in-memory span
* exporter and W3C trace context propagation.
*/
public static OpenTelemetryRule create() {
InMemorySpanExporter spanExporter = InMemorySpanExporter.create();
SdkTracerProvider tracerProvider = SdkTracerProvider.builder().addSpanProcessor(SimpleSpanProcessor.create(spanExporter)).build();
OpenTelemetrySdk openTelemetry = OpenTelemetrySdk.builder().setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance())).setTracerProvider(tracerProvider).build();
return new OpenTelemetryRule(openTelemetry, spanExporter);
}
use of io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter in project opentelemetry-java by open-telemetry.
the class OpenTelemetryExtension method create.
/**
* Returns a {@link OpenTelemetryExtension} with a default SDK initialized with an in-memory span
* exporter and W3C trace context propagation.
*/
public static OpenTelemetryExtension create() {
InMemorySpanExporter spanExporter = InMemorySpanExporter.create();
SdkTracerProvider tracerProvider = SdkTracerProvider.builder().addSpanProcessor(SimpleSpanProcessor.create(spanExporter)).build();
OpenTelemetrySdk openTelemetry = OpenTelemetrySdk.builder().setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance())).setTracerProvider(tracerProvider).build();
return new OpenTelemetryExtension(openTelemetry, spanExporter);
}
Aggregations