use of io.opentelemetry.sdk.trace.SdkTracerProvider in project opentelemetry-java by open-telemetry.
the class AutoConfiguredOpenTelemetrySdkTest method builder_addSamplerCustomizer.
@Test
void builder_addSamplerCustomizer() {
SdkTracerProvider sdkTracerProvider = builder.addSamplerCustomizer((previous, config) -> {
assertThat(previous).isEqualTo(Sampler.parentBased(Sampler.alwaysOn()));
return sampler1;
}).addSamplerCustomizer((previous, config) -> {
assertThat(previous).isSameAs(sampler1);
return sampler2;
}).build().getOpenTelemetrySdk().getSdkTracerProvider();
assertThat(sdkTracerProvider).extracting("sharedState").extracting("sampler").isEqualTo(sampler2);
}
use of io.opentelemetry.sdk.trace.SdkTracerProvider 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.sdk.trace.SdkTracerProvider in project opentelemetry-java by open-telemetry.
the class SpanBuilderShimTest method setAttributes_beforeSpanStart.
@Test
void setAttributes_beforeSpanStart() {
SdkTracerProvider tracerSdkFactory = SdkTracerProvider.builder().setSampler(SamplingPrioritySampler.INSTANCE).build();
Tracer tracer = tracerSdkFactory.get("SpanShimTest");
TelemetryInfo telemetryInfo = new TelemetryInfo(tracer, OpenTracingPropagators.builder().build());
SpanBuilderShim spanBuilder1 = new SpanBuilderShim(telemetryInfo, SPAN_NAME);
SpanBuilderShim spanBuilder2 = new SpanBuilderShim(telemetryInfo, SPAN_NAME);
SpanShim span1 = (SpanShim) spanBuilder1.withTag(SamplingPrioritySampler.SAMPLING_PRIORITY_TAG, SamplingPrioritySampler.UNSAMPLED_VALUE).start();
SpanShim span2 = (SpanShim) spanBuilder2.withTag(SamplingPrioritySampler.SAMPLING_PRIORITY_TAG, SamplingPrioritySampler.SAMPLED_VALUE).start();
assertThat(span1.getSpan().isRecording()).isFalse();
assertThat(span2.getSpan().isRecording()).isTrue();
assertThat(span1.getSpan().getSpanContext().isSampled()).isFalse();
assertThat(span2.getSpan().getSpanContext().isSampled()).isTrue();
}
use of io.opentelemetry.sdk.trace.SdkTracerProvider in project opentelemetry-java by open-telemetry.
the class BatchSpanProcessorTest method continuesIfExporterTimesOut.
@Test
@Timeout(5)
public void continuesIfExporterTimesOut() throws InterruptedException {
int exporterTimeoutMillis = 10;
BatchSpanProcessor bsp = BatchSpanProcessor.builder(mockSpanExporter).setExporterTimeout(exporterTimeoutMillis, TimeUnit.MILLISECONDS).setScheduleDelay(1, TimeUnit.MILLISECONDS).setMaxQueueSize(1).build();
sdkTracerProvider = SdkTracerProvider.builder().addSpanProcessor(bsp).build();
CountDownLatch exported = new CountDownLatch(1);
// We return a result we never complete, meaning it will timeout.
when(mockSpanExporter.export(argThat(spans -> {
assertThat(spans).anySatisfy(span -> assertThat(span.getName()).isEqualTo(SPAN_NAME_1));
exported.countDown();
return true;
}))).thenReturn(new CompletableResultCode());
createEndedSpan(SPAN_NAME_1);
exported.await();
// Timed out so the span was dropped.
await().untilAsserted(() -> assertThat(bsp.getBatch()).isEmpty());
// Still processing new spans.
CountDownLatch exportedAgain = new CountDownLatch(1);
reset(mockSpanExporter);
when(mockSpanExporter.shutdown()).thenReturn(CompletableResultCode.ofSuccess());
when(mockSpanExporter.export(argThat(spans -> {
assertThat(spans).anySatisfy(span -> assertThat(span.getName()).isEqualTo(SPAN_NAME_2));
exportedAgain.countDown();
return true;
}))).thenReturn(CompletableResultCode.ofSuccess());
createEndedSpan(SPAN_NAME_2);
exported.await();
await().untilAsserted(() -> assertThat(bsp.getBatch()).isEmpty());
}
use of io.opentelemetry.sdk.trace.SdkTracerProvider in project opentelemetry-java-contrib by open-telemetry.
the class MojoGoalExecutionHandlerTest method testSpringBootBuildImage_springboot_2.
@Test
public void testSpringBootBuildImage_springboot_2() throws Exception {
String pomXmlPath = "projects/springboot_2/pom.xml";
String mojoGroupId = "org.springframework.boot";
String mojoArtifactId = "spring-boot-maven-plugin";
String mojoVersion = "2.5.6";
String mojoGoal = "build-image";
MavenProject project = newMavenProject(pomXmlPath);
ExecutionEvent executionEvent = newMojoStartedExecutionEvent(project, mojoGroupId, mojoArtifactId, mojoVersion, mojoGoal);
SpringBootBuildImageHandler buildImageHandler = new SpringBootBuildImageHandler();
List<MavenGoal> supportedGoals = buildImageHandler.getSupportedGoals();
assertThat(supportedGoals).isEqualTo(Collections.singletonList(MavenGoal.create(mojoGroupId, mojoArtifactId, mojoGoal)));
try (SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder().build()) {
SpanBuilder spanBuilder = sdkTracerProvider.tracerBuilder("test-tracer").build().spanBuilder("spring-boot:build-image");
buildImageHandler.enrichSpan(spanBuilder, executionEvent);
ReadableSpan span = (ReadableSpan) spanBuilder.startSpan();
// TODO improve the Maven test harness that interpolates the maven properties like
// ${project.artifactId}
assertThat(span.getAttribute(MavenOtelSemanticAttributes.MAVEN_BUILD_CONTAINER_IMAGE_NAME)).isEqualTo("docker.io/john/${project.artifactId}");
assertThat(span.getAttribute(MavenOtelSemanticAttributes.MAVEN_BUILD_CONTAINER_IMAGE_TAGS)).isEqualTo(Collections.singletonList("${project.version}"));
assertThat(span.getAttribute(SemanticAttributes.HTTP_URL)).isEqualTo("https://docker.io");
assertThat(span.getAttribute(SemanticAttributes.PEER_SERVICE)).isEqualTo("docker.io");
assertThat(span.getAttribute(MavenOtelSemanticAttributes.MAVEN_BUILD_CONTAINER_REGISTRY_URL)).isEqualTo("https://docker.io");
}
}
Aggregations