Search in sources :

Example 1 with AiLegacyHeaderSpanProcessor

use of com.microsoft.applicationinsights.agent.internal.legacyheaders.AiLegacyHeaderSpanProcessor in project ApplicationInsights-Java by microsoft.

the class OpenTelemetryConfigurer method configure.

@Override
@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "this method is only called once during initialization")
public void configure(SdkTracerProviderBuilder tracerProvider, ConfigProperties config) {
    TelemetryClient telemetryClient = TelemetryClient.getActive();
    if (telemetryClient == null) {
        // agent failed during startup
        return;
    }
    Configuration configuration = MainEntryPoint.getConfiguration();
    tracerProvider.setSampler(DelegatingSampler.getInstance());
    if (configuration.connectionString != null) {
        if (!configuration.preview.disablePropagation) {
            DelegatingPropagator.getInstance().setUpStandardDelegate(configuration.preview.legacyRequestIdPropagation.enabled);
        }
        DelegatingSampler.getInstance().setDelegate(Samplers.getSampler(configuration.sampling.percentage, configuration));
    } else {
    // in Azure Functions, we configure later on, once we know user has opted in to tracing
    // (note: the default for DelegatingPropagator is to not propagate anything
    // and the default for DelegatingSampler is to not sample anything)
    }
    // operation name span processor is only applied on span start, so doesn't need to be chained
    // with the batch span processor
    tracerProvider.addSpanProcessor(new AiOperationNameSpanProcessor());
    // chained with the batch span processor
    if (!configuration.preview.inheritedAttributes.isEmpty()) {
        tracerProvider.addSpanProcessor(new InheritedAttributesSpanProcessor(configuration.preview.inheritedAttributes));
    }
    // propagator)
    if (configuration.preview.legacyRequestIdPropagation.enabled) {
        tracerProvider.addSpanProcessor(new AiLegacyHeaderSpanProcessor());
    }
    // to be chained with the batch span processor
    if (!configuration.preview.instrumentationKeyOverrides.isEmpty()) {
        tracerProvider.addSpanProcessor(new InheritedInstrumentationKeySpanProcessor(configuration.preview.instrumentationKeyOverrides));
    }
    String tracesExporter = config.getString("otel.traces.exporter");
    if ("none".equals(tracesExporter)) {
        batchSpanProcessor = createExporter(configuration);
        tracerProvider.addSpanProcessor(batchSpanProcessor);
    }
}
Also used : Configuration(com.microsoft.applicationinsights.agent.internal.configuration.Configuration) AiLegacyHeaderSpanProcessor(com.microsoft.applicationinsights.agent.internal.legacyheaders.AiLegacyHeaderSpanProcessor) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

Configuration (com.microsoft.applicationinsights.agent.internal.configuration.Configuration)1 AiLegacyHeaderSpanProcessor (com.microsoft.applicationinsights.agent.internal.legacyheaders.AiLegacyHeaderSpanProcessor)1 TelemetryClient (com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1