use of io.opentelemetry.sdk.trace.SdkTracerProvider in project opentelemetry-java-contrib by open-telemetry.
the class MojoGoalExecutionHandlerTest method testSpringBootBuildImage_springboot_1.
@Test
public void testSpringBootBuildImage_springboot_1() throws Exception {
String pomXmlPath = "projects/springboot_1/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("latest"));
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");
}
}
use of io.opentelemetry.sdk.trace.SdkTracerProvider in project opentelemetry-java-contrib by open-telemetry.
the class MojoGoalExecutionHandlerTest method testMavenDeploy.
@Test
public void testMavenDeploy() throws Exception {
String pomXmlPath = "projects/jar/pom.xml";
String mojoGroupId = "org.apache.maven.plugins";
String mojoArtifactId = "maven-deploy-plugin";
String mojoVersion = "2.8.2";
String mojoGoal = "deploy";
MavenProject project = newMavenProject(pomXmlPath);
ExecutionEvent executionEvent = newMojoStartedExecutionEvent(project, mojoGroupId, mojoArtifactId, mojoVersion, mojoGoal);
MavenDeployHandler mavenDeployHandler = new MavenDeployHandler();
List<MavenGoal> supportedGoals = mavenDeployHandler.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("deploy");
mavenDeployHandler.enrichSpan(spanBuilder, executionEvent);
ReadableSpan span = (ReadableSpan) spanBuilder.startSpan();
assertThat(span.getAttribute(MavenOtelSemanticAttributes.MAVEN_BUILD_REPOSITORY_ID)).isEqualTo("snapshots");
assertThat(span.getAttribute(SemanticAttributes.HTTP_METHOD)).isEqualTo("POST");
assertThat(span.getAttribute(SemanticAttributes.HTTP_URL)).isEqualTo("https://maven.example.com/repository/maven-snapshots/io/opentelemetry/contrib/maven/test-jar/1.0-SNAPSHOT");
assertThat(span.getAttribute(MavenOtelSemanticAttributes.MAVEN_BUILD_REPOSITORY_URL)).isEqualTo("https://maven.example.com/repository/maven-snapshots/");
assertThat(span.getAttribute(SemanticAttributes.PEER_SERVICE)).isEqualTo("maven.example.com");
assertThat(span.getKind()).isEqualTo(SpanKind.CLIENT);
}
}
use of io.opentelemetry.sdk.trace.SdkTracerProvider in project opentelemetry-java-contrib by open-telemetry.
the class AwsXrayRemoteSamplerProviderTest method setEndpoint.
@Test
void setEndpoint() {
Map<String, String> props = new HashMap<>();
props.put("otel.traces.sampler", "xray");
props.put("otel.traces.sampler.arg", "endpoint=http://localhost:3000");
props.put("otel.service.name", "cat-service");
props.put("otel.traces.exporter", "none");
props.put("otel.metrics.exporter", "none");
try (SdkTracerProvider tracerProvider = AutoConfiguredOpenTelemetrySdk.builder().addPropertiesSupplier(() -> props).setResultAsGlobal(false).build().getOpenTelemetrySdk().getSdkTracerProvider()) {
// Inspect implementation details for simplicity, otherwise we'd probably need to make a
// test HTTP server that records requests.
assertThat(tracerProvider).extracting("sharedState").extracting("sampler").isInstanceOfSatisfying(AwsXrayRemoteSampler.class, sampler -> {
assertThat(sampler.getClient().getSamplingRulesEndpoint()).isEqualTo("http://localhost:3000/GetSamplingRules");
assertThat(sampler.getResource().getAttribute(ResourceAttributes.SERVICE_NAME)).isEqualTo("cat-service");
});
}
}
use of io.opentelemetry.sdk.trace.SdkTracerProvider in project opentelemetry-java by open-telemetry.
the class TracerProviderConfigurationTest method configureTracerProvider.
@Test
void configureTracerProvider() {
Map<String, String> properties = new HashMap<>();
properties.put("otel.bsp.schedule.delay", "100000");
properties.put("otel.traces.sampler", "always_off");
properties.put("otel.traces.exporter", "none");
Resource resource = Resource.create(Attributes.builder().put("cat", "meow").build());
// We don't have any exporters on classpath for this test so check no-op case. Exporter cases
// are verified in other test sets like testFullConfig.
SdkTracerProviderBuilder tracerProviderBuilder = SdkTracerProvider.builder().setResource(resource);
TracerProviderConfiguration.configureTracerProvider(tracerProviderBuilder, DefaultConfigProperties.createForTest(properties), TracerProviderConfiguration.class.getClassLoader(), MeterProvider.noop(), (a, unused) -> a, (a, unused) -> a);
SdkTracerProvider tracerProvider = tracerProviderBuilder.build();
try {
assertThat(tracerProvider.getSampler()).isEqualTo(Sampler.alwaysOff());
assertThat(tracerProvider).extracting("sharedState").satisfies(sharedState -> {
assertThat(sharedState).extracting("resource").isEqualTo(resource);
assertThat(sharedState).extracting("activeSpanProcessor").isEqualTo(SpanProcessor.composite());
});
} finally {
tracerProvider.shutdown();
}
}
use of io.opentelemetry.sdk.trace.SdkTracerProvider 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);
}
Aggregations