Skip to content

Commit 8fd45a7

Browse files
authored
Enable retry by default for OTLP exporters (#6588)
1 parent fa215ff commit 8fd45a7

27 files changed

+256
-233
lines changed

exporters/common/src/main/java/io/opentelemetry/exporter/internal/grpc/GrpcExporterBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class GrpcExporterBuilder<T extends Marshaler> {
6060
private final Map<String, String> constantHeaders = new HashMap<>();
6161
private Supplier<Map<String, String>> headerSupplier = Collections::emptyMap;
6262
private TlsConfigHelper tlsConfigHelper = new TlsConfigHelper();
63-
@Nullable private RetryPolicy retryPolicy;
63+
@Nullable private RetryPolicy retryPolicy = RetryPolicy.getDefault();
6464
private Supplier<MeterProvider> meterProviderSupplier = GlobalOpenTelemetry::getMeterProvider;
6565

6666
// Use Object type since gRPC may not be on the classpath.
@@ -137,7 +137,7 @@ public GrpcExporterBuilder<T> setHeadersSupplier(Supplier<Map<String, String>> h
137137
return this;
138138
}
139139

140-
public GrpcExporterBuilder<T> setRetryPolicy(RetryPolicy retryPolicy) {
140+
public GrpcExporterBuilder<T> setRetryPolicy(@Nullable RetryPolicy retryPolicy) {
141141
this.retryPolicy = retryPolicy;
142142
return this;
143143
}

exporters/common/src/main/java/io/opentelemetry/exporter/internal/http/HttpExporterBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public final class HttpExporterBuilder<T extends Marshaler> {
5959
private Supplier<Map<String, String>> headerSupplier = Collections::emptyMap;
6060

6161
private TlsConfigHelper tlsConfigHelper = new TlsConfigHelper();
62-
@Nullable private RetryPolicy retryPolicy;
62+
@Nullable private RetryPolicy retryPolicy = RetryPolicy.getDefault();
6363
private Supplier<MeterProvider> meterProviderSupplier = GlobalOpenTelemetry::getMeterProvider;
6464
@Nullable private Authenticator authenticator;
6565

@@ -128,7 +128,7 @@ public HttpExporterBuilder<T> setMeterProvider(Supplier<MeterProvider> meterProv
128128
return this;
129129
}
130130

131-
public HttpExporterBuilder<T> setRetryPolicy(RetryPolicy retryPolicy) {
131+
public HttpExporterBuilder<T> setRetryPolicy(@Nullable RetryPolicy retryPolicy) {
132132
this.retryPolicy = retryPolicy;
133133
return this;
134134
}

exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/http/logs/OtlpHttpLogRecordExporterBuilder.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Map;
2424
import java.util.concurrent.TimeUnit;
2525
import java.util.function.Supplier;
26+
import javax.annotation.Nullable;
2627
import javax.net.ssl.SSLContext;
2728
import javax.net.ssl.X509TrustManager;
2829

@@ -166,12 +167,12 @@ public OtlpHttpLogRecordExporterBuilder setSslContext(
166167
}
167168

168169
/**
169-
* Set the retry policy. Retry is disabled by default.
170+
* Set the retry policy, or {@code null} to disable retry. Retry policy is {@link
171+
* RetryPolicy#getDefault()} by default
170172
*
171173
* @since 1.28.0
172174
*/
173-
public OtlpHttpLogRecordExporterBuilder setRetryPolicy(RetryPolicy retryPolicy) {
174-
requireNonNull(retryPolicy, "retryPolicy");
175+
public OtlpHttpLogRecordExporterBuilder setRetryPolicy(@Nullable RetryPolicy retryPolicy) {
175176
delegate.setRetryPolicy(retryPolicy);
176177
return this;
177178
}

exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/http/metrics/OtlpHttpMetricExporterBuilder.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Map;
2929
import java.util.concurrent.TimeUnit;
3030
import java.util.function.Supplier;
31+
import javax.annotation.Nullable;
3132
import javax.net.ssl.SSLContext;
3233
import javax.net.ssl.X509TrustManager;
3334

@@ -212,12 +213,12 @@ public OtlpHttpMetricExporterBuilder setDefaultAggregationSelector(
212213
}
213214

214215
/**
215-
* Set the retry policy. Retry is disabled by default.
216+
* Set the retry policy, or {@code null} to disable retry. Retry policy is {@link
217+
* RetryPolicy#getDefault()} by default
216218
*
217219
* @since 1.28.0
218220
*/
219-
public OtlpHttpMetricExporterBuilder setRetryPolicy(RetryPolicy retryPolicy) {
220-
requireNonNull(retryPolicy, "retryPolicy");
221+
public OtlpHttpMetricExporterBuilder setRetryPolicy(@Nullable RetryPolicy retryPolicy) {
221222
delegate.setRetryPolicy(retryPolicy);
222223
return this;
223224
}

exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/http/trace/OtlpHttpSpanExporterBuilder.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Map;
2424
import java.util.concurrent.TimeUnit;
2525
import java.util.function.Supplier;
26+
import javax.annotation.Nullable;
2627
import javax.net.ssl.SSLContext;
2728
import javax.net.ssl.X509TrustManager;
2829

@@ -167,12 +168,12 @@ public OtlpHttpSpanExporterBuilder setSslContext(
167168
}
168169

169170
/**
170-
* Set the retry policy. Retry is disabled by default.
171+
* Set the retry policy, or {@code null} to disable retry. Retry policy is {@link
172+
* RetryPolicy#getDefault()} by default
171173
*
172174
* @since 1.28.0
173175
*/
174-
public OtlpHttpSpanExporterBuilder setRetryPolicy(RetryPolicy retryPolicy) {
175-
requireNonNull(retryPolicy, "retryPolicy");
176+
public OtlpHttpSpanExporterBuilder setRetryPolicy(@Nullable RetryPolicy retryPolicy) {
176177
delegate.setRetryPolicy(retryPolicy);
177178
return this;
178179
}

exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpConfigUtil.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,16 @@ public static void configureOtlpExporterBuilder(
151151
setClientTls.accept(clientKeyBytes, clientKeyChainBytes);
152152
}
153153

154-
boolean retryEnabled =
155-
config.getBoolean("otel.experimental.exporter.otlp.retry.enabled", false);
156-
if (retryEnabled) {
157-
setRetryPolicy.accept(RetryPolicy.getDefault());
154+
Boolean retryDisabled = config.getBoolean("otel.java.exporter.otlp.retry.disabled");
155+
if (retryDisabled == null) {
156+
Boolean experimentalRetryEnabled =
157+
config.getBoolean("otel.experimental.exporter.otlp.retry.enabled");
158+
if (experimentalRetryEnabled != null) {
159+
retryDisabled = !experimentalRetryEnabled;
160+
}
161+
}
162+
if (retryDisabled != null && retryDisabled) {
163+
setRetryPolicy.accept(null);
158164
}
159165

160166
ExporterBuilderUtil.configureExporterMemoryMode(config, setMemoryMode);

exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/logs/OtlpGrpcLogRecordExporterBuilder.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Map;
2525
import java.util.concurrent.TimeUnit;
2626
import java.util.function.Supplier;
27+
import javax.annotation.Nullable;
2728
import javax.net.ssl.SSLContext;
2829
import javax.net.ssl.X509TrustManager;
2930

@@ -210,12 +211,12 @@ public OtlpGrpcLogRecordExporterBuilder setHeaders(Supplier<Map<String, String>>
210211
}
211212

212213
/**
213-
* Set the retry policy. Retry is disabled by default.
214+
* Set the retry policy, or {@code null} to disable retry. Retry policy is {@link
215+
* RetryPolicy#getDefault()} by default
214216
*
215217
* @since 1.28.0
216218
*/
217-
public OtlpGrpcLogRecordExporterBuilder setRetryPolicy(RetryPolicy retryPolicy) {
218-
requireNonNull(retryPolicy, "retryPolicy");
219+
public OtlpGrpcLogRecordExporterBuilder setRetryPolicy(@Nullable RetryPolicy retryPolicy) {
219220
delegate.setRetryPolicy(retryPolicy);
220221
return this;
221222
}

exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/metrics/OtlpGrpcMetricExporterBuilder.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.Map;
3030
import java.util.concurrent.TimeUnit;
3131
import java.util.function.Supplier;
32+
import javax.annotation.Nullable;
3233
import javax.net.ssl.SSLContext;
3334
import javax.net.ssl.X509TrustManager;
3435

@@ -256,12 +257,12 @@ public OtlpGrpcMetricExporterBuilder setDefaultAggregationSelector(
256257
}
257258

258259
/**
259-
* Set the retry policy. Retry is disabled by default.
260+
* Set the retry policy, or {@code null} to disable retry. Retry policy is {@link
261+
* RetryPolicy#getDefault()} by default
260262
*
261263
* @since 1.28.0
262264
*/
263-
public OtlpGrpcMetricExporterBuilder setRetryPolicy(RetryPolicy retryPolicy) {
264-
requireNonNull(retryPolicy, "retryPolicy");
265+
public OtlpGrpcMetricExporterBuilder setRetryPolicy(@Nullable RetryPolicy retryPolicy) {
265266
delegate.setRetryPolicy(retryPolicy);
266267
return this;
267268
}

exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/trace/OtlpGrpcSpanExporterBuilder.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Map;
2525
import java.util.concurrent.TimeUnit;
2626
import java.util.function.Supplier;
27+
import javax.annotation.Nullable;
2728
import javax.net.ssl.SSLContext;
2829
import javax.net.ssl.X509TrustManager;
2930

@@ -207,12 +208,12 @@ public OtlpGrpcSpanExporterBuilder setHeaders(Supplier<Map<String, String>> head
207208
}
208209

209210
/**
210-
* Set the retry policy. Retry is disabled by default.
211+
* Set the retry policy, or {@code null} to disable retry. Retry policy is {@link
212+
* RetryPolicy#getDefault()} by default
211213
*
212214
* @since 1.28.0
213215
*/
214-
public OtlpGrpcSpanExporterBuilder setRetryPolicy(RetryPolicy retryPolicy) {
215-
requireNonNull(retryPolicy, "retryPolicy");
216+
public OtlpGrpcSpanExporterBuilder setRetryPolicy(@Nullable RetryPolicy retryPolicy) {
216217
delegate.setRetryPolicy(retryPolicy);
217218
return this;
218219
}

exporters/otlp/all/src/test/java/io/opentelemetry/exporter/otlp/internal/OtlpLogRecordExporterProviderTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void createExporter_GrpcDefaults() {
127127
verify(grpcBuilder, never()).setTimeout(any());
128128
verify(grpcBuilder, never()).setTrustedCertificates(any());
129129
verify(grpcBuilder, never()).setClientTls(any(), any());
130-
assertThat(grpcBuilder).extracting("delegate").extracting("retryPolicy").isNull();
130+
assertThat(grpcBuilder).extracting("delegate").extracting("retryPolicy").isNotNull();
131131
assertThat(exporter).extracting("memoryMode").isEqualTo(MemoryMode.IMMUTABLE_DATA);
132132
}
133133
Mockito.verifyNoInteractions(httpBuilder);
@@ -143,7 +143,7 @@ void createExporter_GrpcWithGeneralConfiguration() throws CertificateEncodingExc
143143
config.put("otel.exporter.otlp.headers", "header-key=header-value");
144144
config.put("otel.exporter.otlp.compression", "gzip");
145145
config.put("otel.exporter.otlp.timeout", "15s");
146-
config.put("otel.experimental.exporter.otlp.retry.enabled", "true");
146+
config.put("otel.java.exporter.otlp.retry.disabled", "true");
147147

148148
try (LogRecordExporter exporter =
149149
provider.createExporter(DefaultConfigProperties.createFromMap(config))) {
@@ -156,7 +156,7 @@ void createExporter_GrpcWithGeneralConfiguration() throws CertificateEncodingExc
156156
verify(grpcBuilder).setTrustedCertificates(serverTls.certificate().getEncoded());
157157
verify(grpcBuilder)
158158
.setClientTls(clientTls.privateKey().getEncoded(), clientTls.certificate().getEncoded());
159-
assertThat(grpcBuilder).extracting("delegate").extracting("retryPolicy").isNotNull();
159+
assertThat(grpcBuilder).extracting("delegate").extracting("retryPolicy").isNull();
160160
}
161161
Mockito.verifyNoInteractions(httpBuilder);
162162
}
@@ -210,7 +210,7 @@ void createExporter_HttpDefaults() {
210210
verify(httpBuilder, never()).setTimeout(any());
211211
verify(httpBuilder, never()).setTrustedCertificates(any());
212212
verify(httpBuilder, never()).setClientTls(any(), any());
213-
assertThat(httpBuilder).extracting("delegate").extracting("retryPolicy").isNull();
213+
assertThat(httpBuilder).extracting("delegate").extracting("retryPolicy").isNotNull();
214214
assertThat(exporter).extracting("memoryMode").isEqualTo(MemoryMode.IMMUTABLE_DATA);
215215
}
216216
Mockito.verifyNoInteractions(grpcBuilder);
@@ -227,7 +227,7 @@ void createExporter_HttpWithGeneralConfiguration() throws CertificateEncodingExc
227227
config.put("otel.exporter.otlp.headers", "header-key=header-value");
228228
config.put("otel.exporter.otlp.compression", "gzip");
229229
config.put("otel.exporter.otlp.timeout", "15s");
230-
config.put("otel.experimental.exporter.otlp.retry.enabled", "true");
230+
config.put("otel.java.exporter.otlp.retry.disabled", "true");
231231

232232
try (LogRecordExporter exporter =
233233
provider.createExporter(DefaultConfigProperties.createFromMap(config))) {
@@ -240,7 +240,7 @@ void createExporter_HttpWithGeneralConfiguration() throws CertificateEncodingExc
240240
verify(httpBuilder).setTrustedCertificates(serverTls.certificate().getEncoded());
241241
verify(httpBuilder)
242242
.setClientTls(clientTls.privateKey().getEncoded(), clientTls.certificate().getEncoded());
243-
assertThat(httpBuilder).extracting("delegate").extracting("retryPolicy").isNotNull();
243+
assertThat(httpBuilder).extracting("delegate").extracting("retryPolicy").isNull();
244244
}
245245
Mockito.verifyNoInteractions(grpcBuilder);
246246
}

0 commit comments

Comments
 (0)