Search in sources :

Example 1 with LogEmitterProvider

use of io.opentelemetry.instrumentation.api.appender.internal.LogEmitterProvider 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;
}
Also used : AutoConfiguredOpenTelemetrySdkBuilder(io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder) AgentLogEmitterProvider(io.opentelemetry.javaagent.instrumentation.api.appender.internal.AgentLogEmitterProvider) DelegatingLogEmitterProvider(io.opentelemetry.instrumentation.sdk.appender.internal.DelegatingLogEmitterProvider) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) LogEmitterProvider(io.opentelemetry.instrumentation.api.appender.internal.LogEmitterProvider) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) AutoConfiguredOpenTelemetrySdk(io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) AutoConfiguredOpenTelemetrySdk(io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk) OpenTelemetrySdk(io.opentelemetry.sdk.OpenTelemetrySdk)

Aggregations

LogEmitterProvider (io.opentelemetry.instrumentation.api.appender.internal.LogEmitterProvider)1 DelegatingLogEmitterProvider (io.opentelemetry.instrumentation.sdk.appender.internal.DelegatingLogEmitterProvider)1 AgentLogEmitterProvider (io.opentelemetry.javaagent.instrumentation.api.appender.internal.AgentLogEmitterProvider)1 OpenTelemetrySdk (io.opentelemetry.sdk.OpenTelemetrySdk)1 AutoConfiguredOpenTelemetrySdk (io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk)1 AutoConfiguredOpenTelemetrySdkBuilder (io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder)1 CompletableResultCode (io.opentelemetry.sdk.common.CompletableResultCode)1 SdkLogEmitterProvider (io.opentelemetry.sdk.logs.SdkLogEmitterProvider)1