From 1cd5b1537202331fe9785a9178c0789001e0b5bc Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 10 Mar 2022 12:58:14 -0800 Subject: [PATCH] Add BSP configuration option (#2165) * Add BSP configuration option * Rename env var to match otel --- .../init/OpenTelemetryConfigurer.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/OpenTelemetryConfigurer.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/OpenTelemetryConfigurer.java index 28070319bae..8d63b092934 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/OpenTelemetryConfigurer.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/OpenTelemetryConfigurer.java @@ -43,8 +43,10 @@ import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; +import io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder; import io.opentelemetry.sdk.trace.export.SpanExporter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.time.Duration; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -161,9 +163,20 @@ private static BatchSpanProcessor createExporter(Configuration configuration) { } // using BatchSpanProcessor in order to get off of the application thread as soon as possible - // 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 - return BatchSpanProcessor.builder(currExporter).setMaxExportBatchSize(1).build(); + 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.setScheduleDelay(Duration.ofMillis(100)).build(); } private static class BackCompatHttpUrlProcessor implements SpanExporter {