|
43 | 43 | import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; |
44 | 44 | import io.opentelemetry.sdk.trace.data.SpanData; |
45 | 45 | import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; |
| 46 | +import io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder; |
46 | 47 | import io.opentelemetry.sdk.trace.export.SpanExporter; |
47 | 48 | import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; |
| 49 | +import java.time.Duration; |
48 | 50 | import java.util.ArrayList; |
49 | 51 | import java.util.Collection; |
50 | 52 | import java.util.Collections; |
@@ -161,9 +163,20 @@ private static BatchSpanProcessor createExporter(Configuration configuration) { |
161 | 163 | } |
162 | 164 |
|
163 | 165 | // 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(); |
167 | 180 | } |
168 | 181 |
|
169 | 182 | private static class BackCompatHttpUrlProcessor implements SpanExporter { |
|
0 commit comments