Skip to content

Commit 1cd5b15

Browse files
authored
Add BSP configuration option (#2165)
* Add BSP configuration option * Rename env var to match otel
1 parent 5619f0f commit 1cd5b15

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/OpenTelemetryConfigurer.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343
import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder;
4444
import io.opentelemetry.sdk.trace.data.SpanData;
4545
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
46+
import io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder;
4647
import io.opentelemetry.sdk.trace.export.SpanExporter;
4748
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
49+
import java.time.Duration;
4850
import java.util.ArrayList;
4951
import java.util.Collection;
5052
import java.util.Collections;
@@ -161,9 +163,20 @@ private static BatchSpanProcessor createExporter(Configuration configuration) {
161163
}
162164

163165
// using BatchSpanProcessor in order to get off of the application thread as soon as possible
164-
// using batch size 1 because need to convert to SpanData as soon as possible to grab data for
165-
// live metrics. the real batching is done at a lower level
166-
return BatchSpanProcessor.builder(currExporter).setMaxExportBatchSize(1).build();
166+
BatchSpanProcessorBuilder builder = BatchSpanProcessor.builder(currExporter);
167+
168+
String delayMillisStr = System.getenv("APPLICATIONINSIGHTS_PREVIEW_BSP_SCHEDULE_DELAY");
169+
if (delayMillisStr != null) {
170+
// experimenting with flushing at small interval instead of using batch size 1
171+
// (suspect this may be better performance on small containers)
172+
builder.setScheduleDelay(Duration.ofMillis(Integer.parseInt(delayMillisStr)));
173+
} else {
174+
// using batch size 1 because need to convert to SpanData as soon as possible to grab data for
175+
// live metrics. the real batching is done at a lower level
176+
builder.setMaxExportBatchSize(1);
177+
}
178+
179+
return builder.setScheduleDelay(Duration.ofMillis(100)).build();
167180
}
168181

169182
private static class BackCompatHttpUrlProcessor implements SpanExporter {

0 commit comments

Comments
 (0)