33import static datadog .communication .http .OkHttpUtils .buildHttpClient ;
44import static datadog .communication .http .OkHttpUtils .gzippedRequestBodyOf ;
55import static datadog .communication .http .OkHttpUtils .isPlainHttp ;
6+ import static datadog .communication .http .OkHttpUtils .sendWithRetries ;
67
8+ import datadog .communication .http .HttpRetryPolicy ;
79import datadog .logging .RatelimitedLogger ;
810import datadog .trace .api .config .OtlpConfig .Compression ;
911import 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
0 commit comments