use of io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class OpenTelemetryInstaller method installOpenTelemetrySdk.
/**
* Install the {@link OpenTelemetrySdk} using autoconfigure, and return the {@link
* AutoConfiguredOpenTelemetrySdk}.
*
* @return the {@link AutoConfiguredOpenTelemetrySdk}
*/
static AutoConfiguredOpenTelemetrySdk installOpenTelemetrySdk(Config config) {
System.setProperty("io.opentelemetry.context.contextStorageProvider", "default");
AutoConfiguredOpenTelemetrySdkBuilder builder = AutoConfiguredOpenTelemetrySdk.builder().setResultAsGlobal(true).addPropertiesSupplier(config::getAllProperties);
ClassLoader classLoader = AgentInitializer.getExtensionsClassLoader();
if (classLoader != null) {
// May be null in unit tests.
builder.setServiceClassLoader(classLoader);
}
AutoConfiguredOpenTelemetrySdk autoConfiguredSdk = builder.build();
OpenTelemetrySdk sdk = autoConfiguredSdk.getOpenTelemetrySdk();
OpenTelemetrySdkAccess.internalSetForceFlush((timeout, unit) -> {
CompletableResultCode traceResult = sdk.getSdkTracerProvider().forceFlush();
CompletableResultCode metricsResult = sdk.getSdkMeterProvider().forceFlush();
CompletableResultCode.ofAll(Arrays.asList(traceResult, metricsResult)).join(timeout, unit);
});
SdkLogEmitterProvider sdkLogEmitterProvider = autoConfiguredSdk.getOpenTelemetrySdk().getSdkLogEmitterProvider();
LogEmitterProvider logEmitterProvider = DelegatingLogEmitterProvider.from(sdkLogEmitterProvider);
AgentLogEmitterProvider.set(logEmitterProvider);
return autoConfiguredSdk;
}
use of io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder in project opentelemetry-plugin by jenkinsci.
the class OpenTelemetrySdkProvider method initialize.
public void initialize(@Nonnull OpenTelemetryConfiguration configuration) {
// shutdown existing SDK
preDestroy();
AutoConfiguredOpenTelemetrySdkBuilder sdkBuilder = AutoConfiguredOpenTelemetrySdk.builder();
// PROPERTIES
sdkBuilder.addPropertiesSupplier(() -> configuration.toOpenTelemetryProperties());
// RESOURCE
sdkBuilder.addResourceCustomizer((resource, configProperties) -> {
ResourceBuilder resourceBuilder = Resource.builder().putAll(resource).putAll(configuration.toOpenTelemetryResource());
return resourceBuilder.build();
});
sdkBuilder.registerShutdownHook(// SDK closed by io.jenkins.plugins.opentelemetry.OpenTelemetrySdkProvider.preDestroy()
false).setResultAsGlobal(// ensure GlobalOpenTelemetry.set() is invoked
true);
AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk = sdkBuilder.build();
this.openTelemetrySdk = autoConfiguredOpenTelemetrySdk.getOpenTelemetrySdk();
this.resource = autoConfiguredOpenTelemetrySdk.getResource();
this.config = autoConfiguredOpenTelemetrySdk.getConfig();
this.openTelemetry = this.openTelemetrySdk;
this.tracer.setDelegate(openTelemetry.getTracer(GlobalOpenTelemetrySdk.INSTRUMENTATION_NAME, OtelUtils.getOpentelemetryPluginVersion()));
this.logEmitter = openTelemetrySdk.getSdkLogEmitterProvider().get(GlobalOpenTelemetrySdk.INSTRUMENTATION_NAME);
this.meter = openTelemetry.getMeterProvider().get(GlobalOpenTelemetrySdk.INSTRUMENTATION_NAME);
LOGGER.log(Level.INFO, () -> "OpenTelemetry SDK initialized: " + OtelUtils.prettyPrintOtelSdkConfig(autoConfiguredOpenTelemetrySdk));
}
Aggregations