Search in sources :

Example 1 with ExporterWithSpanProcessor

use of com.microsoft.applicationinsights.agent.internal.processors.ExporterWithSpanProcessor in project ApplicationInsights-Java by microsoft.

the class OpenTelemetryConfigurer method createExporter.

private static BatchSpanProcessor createExporter(Configuration configuration) {
    List<ProcessorConfig> processors = configuration.preview.processors.stream().filter(processor -> processor.type != Configuration.ProcessorType.METRIC_FILTER).collect(Collectors.toCollection(ArrayList::new));
    // Reversing the order of processors before passing it to SpanProcessor
    Collections.reverse(processors);
    SpanExporter currExporter = new Exporter(TelemetryClient.getActive(), configuration.preview.captureHttpServer4xxAsError);
    // flushing TelemetryClient
    if (!processors.isEmpty()) {
        for (ProcessorConfig processorConfig : processors) {
            switch(processorConfig.type) {
                case ATTRIBUTE:
                    currExporter = new ExporterWithAttributeProcessor(processorConfig, currExporter);
                    break;
                case SPAN:
                    currExporter = new ExporterWithSpanProcessor(processorConfig, currExporter);
                    break;
                case LOG:
                    currExporter = new ExporterWithLogProcessor(processorConfig, currExporter);
                    break;
                default:
                    throw new IllegalStateException("Not an expected ProcessorType: " + processorConfig.type);
            }
        }
        // this is temporary until semantic attributes stabilize and we make breaking change
        // then can use java.util.functions.Predicate<Attributes>
        currExporter = new BackCompatHttpUrlProcessor(currExporter);
    }
    // using BatchSpanProcessor in order to get off of the application thread as soon as possible
    BatchSpanProcessorBuilder builder = BatchSpanProcessor.builder(currExporter);
    String delayMillisStr = System.getenv("APPLICATIONINSIGHTS_PREVIEW_BSP_SCHEDULE_DELAY");
    if (delayMillisStr != null) {
        // experimenting with flushing at small interval instead of using batch size 1
        // (suspect this may be better performance on small containers)
        builder.setScheduleDelay(Duration.ofMillis(Integer.parseInt(delayMillisStr)));
    } else {
        // using batch size 1 because need to convert to SpanData as soon as possible to grab data for
        // live metrics. the real batching is done at a lower level
        builder.setMaxExportBatchSize(1);
    }
    return builder.build();
}
Also used : ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) AiLegacyHeaderSpanProcessor(com.microsoft.applicationinsights.agent.internal.legacyheaders.AiLegacyHeaderSpanProcessor) Samplers(com.microsoft.applicationinsights.agent.internal.sampling.Samplers) SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) Attributes(io.opentelemetry.api.common.Attributes) DelegatingPropagator(com.microsoft.applicationinsights.agent.internal.legacyheaders.DelegatingPropagator) ArrayList(java.util.ArrayList) SdkTracerProviderConfigurer(io.opentelemetry.sdk.autoconfigure.spi.traces.SdkTracerProviderConfigurer) ProcessorConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig) Duration(java.time.Duration) DelegatingSampler(com.microsoft.applicationinsights.agent.internal.sampling.DelegatingSampler) BatchSpanProcessor(io.opentelemetry.sdk.trace.export.BatchSpanProcessor) Configuration(com.microsoft.applicationinsights.agent.internal.configuration.Configuration) Collection(java.util.Collection) ExporterWithLogProcessor(com.microsoft.applicationinsights.agent.internal.processors.ExporterWithLogProcessor) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) SdkTracerProviderBuilder(io.opentelemetry.sdk.trace.SdkTracerProviderBuilder) Collectors(java.util.stream.Collectors) MySpanData(com.microsoft.applicationinsights.agent.internal.processors.MySpanData) AttributesBuilder(io.opentelemetry.api.common.AttributesBuilder) Exporter(com.microsoft.applicationinsights.agent.internal.exporter.Exporter) List(java.util.List) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) AutoService(com.google.auto.service.AutoService) SpanData(io.opentelemetry.sdk.trace.data.SpanData) ExporterWithAttributeProcessor(com.microsoft.applicationinsights.agent.internal.processors.ExporterWithAttributeProcessor) ExporterWithSpanProcessor(com.microsoft.applicationinsights.agent.internal.processors.ExporterWithSpanProcessor) BatchSpanProcessorBuilder(io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder) Collections(java.util.Collections) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) ExporterWithSpanProcessor(com.microsoft.applicationinsights.agent.internal.processors.ExporterWithSpanProcessor) ExporterWithLogProcessor(com.microsoft.applicationinsights.agent.internal.processors.ExporterWithLogProcessor) ExporterWithAttributeProcessor(com.microsoft.applicationinsights.agent.internal.processors.ExporterWithAttributeProcessor) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) BatchSpanProcessorBuilder(io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) Exporter(com.microsoft.applicationinsights.agent.internal.exporter.Exporter) ProcessorConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig)

Aggregations

AutoService (com.google.auto.service.AutoService)1 Configuration (com.microsoft.applicationinsights.agent.internal.configuration.Configuration)1 ProcessorConfig (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig)1 Exporter (com.microsoft.applicationinsights.agent.internal.exporter.Exporter)1 AiLegacyHeaderSpanProcessor (com.microsoft.applicationinsights.agent.internal.legacyheaders.AiLegacyHeaderSpanProcessor)1 DelegatingPropagator (com.microsoft.applicationinsights.agent.internal.legacyheaders.DelegatingPropagator)1 ExporterWithAttributeProcessor (com.microsoft.applicationinsights.agent.internal.processors.ExporterWithAttributeProcessor)1 ExporterWithLogProcessor (com.microsoft.applicationinsights.agent.internal.processors.ExporterWithLogProcessor)1 ExporterWithSpanProcessor (com.microsoft.applicationinsights.agent.internal.processors.ExporterWithSpanProcessor)1 MySpanData (com.microsoft.applicationinsights.agent.internal.processors.MySpanData)1 DelegatingSampler (com.microsoft.applicationinsights.agent.internal.sampling.DelegatingSampler)1 Samplers (com.microsoft.applicationinsights.agent.internal.sampling.Samplers)1 TelemetryClient (com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Attributes (io.opentelemetry.api.common.Attributes)1 AttributesBuilder (io.opentelemetry.api.common.AttributesBuilder)1 ConfigProperties (io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties)1 SdkTracerProviderConfigurer (io.opentelemetry.sdk.autoconfigure.spi.traces.SdkTracerProviderConfigurer)1 CompletableResultCode (io.opentelemetry.sdk.common.CompletableResultCode)1 SdkTracerProviderBuilder (io.opentelemetry.sdk.trace.SdkTracerProviderBuilder)1