Skip to content

Commit

Permalink
Add BSP configuration option (#2165)
Browse files Browse the repository at this point in the history
* Add BSP configuration option

* Rename env var to match otel
  • Loading branch information
trask authored Mar 10, 2022
1 parent 5619f0f commit 1cd5b15
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1cd5b15

Please sign in to comment.