Skip to content

Commit 1ed021a

Browse files
committed
Add random jitter when starting OtlpMetricsService
Avoids a fleet of apps starting at the same time from exporting OTLP metrics in sync
1 parent d644ab1 commit 1ed021a

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

dd-trace-core/src/main/java/datadog/trace/core/otlp/metrics/OtlpMetricsService.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import datadog.trace.core.otlp.common.OtlpPayload;
99
import datadog.trace.core.otlp.common.OtlpSender;
1010
import datadog.trace.util.AgentTaskScheduler;
11+
import java.util.concurrent.ThreadLocalRandom;
1112
import java.util.concurrent.TimeUnit;
1213
import org.slf4j.Logger;
1314
import org.slf4j.LoggerFactory;
@@ -58,8 +59,19 @@ private OtlpMetricsService(Config config) {
5859
}
5960

6061
public void start() {
62+
// add random jitter of up to 5 seconds to initial delay; avoids a fleet
63+
// of apps starting at the same time from exporting OTLP metrics in sync
64+
long initialMillis =
65+
intervalMillis
66+
+ Math.min(
67+
(long)
68+
(500d
69+
* Math.log(ThreadLocalRandom.current().nextDouble())
70+
/ Math.log(1 - 0.25)),
71+
5_000);
72+
6173
scheduler.scheduleAtFixedRate(
62-
this::export, intervalMillis, intervalMillis, TimeUnit.MILLISECONDS);
74+
this::export, initialMillis, intervalMillis, TimeUnit.MILLISECONDS);
6375
}
6476

6577
public void flush() {

0 commit comments

Comments
 (0)