Skip to content

Commit e5a7dcc

Browse files
committed
Add retry policy to OTLP exports
1 parent feb248c commit e5a7dcc

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

dd-trace-core/src/main/java/datadog/trace/core/otlp/common/OtlpHttpSender.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import static datadog.communication.http.OkHttpUtils.buildHttpClient;
44
import static datadog.communication.http.OkHttpUtils.gzippedRequestBodyOf;
55
import static datadog.communication.http.OkHttpUtils.isPlainHttp;
6+
import static datadog.communication.http.OkHttpUtils.sendWithRetries;
67

8+
import datadog.communication.http.HttpRetryPolicy;
79
import datadog.logging.RatelimitedLogger;
810
import datadog.trace.api.config.OtlpConfig.Compression;
911
import java.io.IOException;
@@ -23,19 +25,26 @@ public final class OtlpHttpSender implements OtlpSender {
2325
private static final RatelimitedLogger RATELIMITED_LOGGER =
2426
new RatelimitedLogger(LOGGER, 5, TimeUnit.MINUTES);
2527

28+
private final HttpRetryPolicy.Factory retryPolicy =
29+
new HttpRetryPolicy.Factory(5, 100, 2.0, true);
30+
2631
private final HttpUrl url;
2732
private final Map<String, String> headers;
2833
private final boolean gzip;
2934

3035
private final OkHttpClient client;
3136

3237
public OtlpHttpSender(
33-
String endpoint, Map<String, String> headers, int timeoutMillis, Compression compression) {
38+
String endpoint,
39+
String signalPath,
40+
Map<String, String> headers,
41+
int timeoutMillis,
42+
Compression compression) {
3443

3544
String unixDomainSocketPath;
3645
if (endpoint.startsWith("unix://")) {
3746
unixDomainSocketPath = endpoint.substring(7);
38-
this.url = HttpUrl.get("http://localhost:4318");
47+
this.url = HttpUrl.get("http://localhost:4318" + signalPath);
3948
} else {
4049
unixDomainSocketPath = null;
4150
this.url = HttpUrl.get(endpoint);
@@ -51,13 +60,18 @@ public void send(OtlpPayload payload) {
5160
if (payload == OtlpPayload.EMPTY) {
5261
return; // nothing to send
5362
}
54-
try (final Response response = client.newCall(makeRequest(payload)).execute()) {
63+
Request request = makeRequest(payload);
64+
try (Response response = sendWithRetries(client, retryPolicy, request)) {
5565
if (!response.isSuccessful()) {
5666
RATELIMITED_LOGGER.warn(
57-
"OTLP export failed with status {}: {}", response.code(), response.message());
67+
"OTLP export to {} failed with status {}: {}",
68+
request.url(),
69+
response.code(),
70+
response.message());
5871
}
5972
} catch (IOException e) {
60-
RATELIMITED_LOGGER.warn("OTLP export failed with exception: {}", e.toString());
73+
RATELIMITED_LOGGER.warn(
74+
"OTLP export to {} failed with exception: {}", request.url(), e.toString());
6175
}
6276
}
6377

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ private OtlpMetricsService(Config config) {
2424
this.sender =
2525
new OtlpHttpSender(
2626
config.getOtlpMetricsEndpoint(),
27+
"/v1/metrics",
2728
config.getOtlpMetricsHeaders(),
2829
config.getOtlpMetricsTimeout(),
2930
config.getOtlpMetricsCompression());

0 commit comments

Comments
 (0)