Skip to content

Commit 0673fcf

Browse files
authored
Add support for setting OTLP exporter executor service (#7152)
1 parent a3dd677 commit 0673fcf

File tree

34 files changed

+442
-34
lines changed

34 files changed

+442
-34
lines changed
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
11
Comparing source compatibility of opentelemetry-exporter-otlp-1.49.0-SNAPSHOT.jar against opentelemetry-exporter-otlp-1.48.0.jar
2-
No changes.
2+
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder (not serializable)
3+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
4+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder setExecutorService(java.util.concurrent.ExecutorService)
5+
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder (not serializable)
6+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
7+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder setExecutorService(java.util.concurrent.ExecutorService)
8+
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder (not serializable)
9+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
10+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder setExecutorService(java.util.concurrent.ExecutorService)
11+
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder (not serializable)
12+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
13+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder setExecutorService(java.util.concurrent.ExecutorService)
14+
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder (not serializable)
15+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
16+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder setExecutorService(java.util.concurrent.ExecutorService)
17+
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder (not serializable)
18+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
19+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder setExecutorService(java.util.concurrent.ExecutorService)

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Optional;
2626
import java.util.ServiceLoader;
2727
import java.util.StringJoiner;
28+
import java.util.concurrent.ExecutorService;
2829
import java.util.concurrent.TimeUnit;
2930
import java.util.function.BiFunction;
3031
import java.util.function.Supplier;
@@ -63,6 +64,7 @@ public class GrpcExporterBuilder<T extends Marshaler> {
6364
@Nullable private RetryPolicy retryPolicy = RetryPolicy.getDefault();
6465
private Supplier<MeterProvider> meterProviderSupplier = GlobalOpenTelemetry::getMeterProvider;
6566
private ClassLoader serviceClassLoader = GrpcExporterBuilder.class.getClassLoader();
67+
@Nullable private ExecutorService executorService;
6668

6769
// Use Object type since gRPC may not be on the classpath.
6870
@Nullable private Object grpcChannel;
@@ -153,6 +155,11 @@ public GrpcExporterBuilder<T> setServiceClassLoader(ClassLoader servieClassLoade
153155
return this;
154156
}
155157

158+
public GrpcExporterBuilder<T> setExecutorService(ExecutorService executorService) {
159+
this.executorService = executorService;
160+
return this;
161+
}
162+
156163
@SuppressWarnings("BuilderReturnThis")
157164
public GrpcExporterBuilder<T> copy() {
158165
GrpcExporterBuilder<T> copy =
@@ -216,7 +223,8 @@ public GrpcExporter<T> build() {
216223
grpcStubFactory,
217224
retryPolicy,
218225
isPlainHttp ? null : tlsConfigHelper.getSslContext(),
219-
isPlainHttp ? null : tlsConfigHelper.getTrustManager()));
226+
isPlainHttp ? null : tlsConfigHelper.getTrustManager(),
227+
executorService));
220228
LOGGER.log(Level.FINE, "Using GrpcSender: " + grpcSender.getClass().getName());
221229

222230
return new GrpcExporter<>(exporterName, type, grpcSender, meterProviderSupplier);
@@ -250,6 +258,9 @@ public String toString(boolean includePrefixAndSuffix) {
250258
joiner.add("grpcChannel=" + grpcChannel);
251259
}
252260
joiner.add("serviceClassLoader=" + serviceClassLoader);
261+
if (executorService != null) {
262+
joiner.add("executorService=" + executorService);
263+
}
253264
// Note: omit tlsConfigHelper because we can't log the configuration in any readable way
254265
// Note: omit meterProviderSupplier because we can't log the configuration in any readable way
255266
return joiner.toString();

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.net.URI;
1414
import java.util.List;
1515
import java.util.Map;
16+
import java.util.concurrent.ExecutorService;
1617
import java.util.function.BiFunction;
1718
import java.util.function.Supplier;
1819
import javax.annotation.Nullable;
@@ -40,7 +41,8 @@ public static <T extends Marshaler> GrpcSenderConfig<T> create(
4041
Supplier<BiFunction<Channel, String, MarshalerServiceStub<T, ?, ?>>> stubFactory,
4142
@Nullable RetryPolicy retryPolicy,
4243
@Nullable SSLContext sslContext,
43-
@Nullable X509TrustManager trustManager) {
44+
@Nullable X509TrustManager trustManager,
45+
@Nullable ExecutorService executorService) {
4446
return new AutoValue_GrpcSenderConfig<>(
4547
endpoint,
4648
endpointPath,
@@ -52,7 +54,8 @@ public static <T extends Marshaler> GrpcSenderConfig<T> create(
5254
stubFactory,
5355
retryPolicy,
5456
sslContext,
55-
trustManager);
57+
trustManager,
58+
executorService);
5659
}
5760

5861
public abstract URI getEndpoint();
@@ -82,4 +85,7 @@ public static <T extends Marshaler> GrpcSenderConfig<T> create(
8285

8386
@Nullable
8487
public abstract X509TrustManager getTrustManager();
88+
89+
@Nullable
90+
public abstract ExecutorService getExecutorService();
8591
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Optional;
2424
import java.util.ServiceLoader;
2525
import java.util.StringJoiner;
26+
import java.util.concurrent.ExecutorService;
2627
import java.util.concurrent.TimeUnit;
2728
import java.util.function.Supplier;
2829
import java.util.logging.Level;
@@ -61,6 +62,7 @@ public final class HttpExporterBuilder<T extends Marshaler> {
6162
@Nullable private RetryPolicy retryPolicy = RetryPolicy.getDefault();
6263
private Supplier<MeterProvider> meterProviderSupplier = GlobalOpenTelemetry::getMeterProvider;
6364
private ClassLoader serviceClassLoader = HttpExporterBuilder.class.getClassLoader();
65+
@Nullable private ExecutorService executorService;
6466

6567
public HttpExporterBuilder(String exporterName, String type, String defaultEndpoint) {
6668
this.exporterName = exporterName;
@@ -137,6 +139,11 @@ public HttpExporterBuilder<T> setServiceClassLoader(ClassLoader servieClassLoade
137139
return this;
138140
}
139141

142+
public HttpExporterBuilder<T> setExecutorService(ExecutorService executorService) {
143+
this.executorService = executorService;
144+
return this;
145+
}
146+
140147
public HttpExporterBuilder<T> exportAsJson() {
141148
this.exportAsJson = true;
142149
return this;
@@ -198,7 +205,8 @@ public HttpExporter<T> build() {
198205
proxyOptions,
199206
retryPolicy,
200207
isPlainHttp ? null : tlsConfigHelper.getSslContext(),
201-
isPlainHttp ? null : tlsConfigHelper.getTrustManager()));
208+
isPlainHttp ? null : tlsConfigHelper.getTrustManager(),
209+
executorService));
202210
LOGGER.log(Level.FINE, "Using HttpSender: " + httpSender.getClass().getName());
203211

204212
return new HttpExporter<>(exporterName, type, httpSender, meterProviderSupplier, exportAsJson);
@@ -230,6 +238,9 @@ public String toString(boolean includePrefixAndSuffix) {
230238
joiner.add("retryPolicy=" + retryPolicy);
231239
}
232240
joiner.add("serviceClassLoader=" + serviceClassLoader);
241+
if (executorService != null) {
242+
joiner.add("executorService=" + executorService);
243+
}
233244
// Note: omit tlsConfigHelper because we can't log the configuration in any readable way
234245
// Note: omit meterProviderSupplier because we can't log the configuration in any readable way
235246
return joiner.toString();

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.opentelemetry.sdk.common.export.RetryPolicy;
1212
import java.util.List;
1313
import java.util.Map;
14+
import java.util.concurrent.ExecutorService;
1415
import java.util.function.Supplier;
1516
import javax.annotation.Nullable;
1617
import javax.annotation.concurrent.Immutable;
@@ -37,7 +38,8 @@ public static HttpSenderConfig create(
3738
@Nullable ProxyOptions proxyOptions,
3839
@Nullable RetryPolicy retryPolicy,
3940
@Nullable SSLContext sslContext,
40-
@Nullable X509TrustManager trustManager) {
41+
@Nullable X509TrustManager trustManager,
42+
@Nullable ExecutorService executorService) {
4143
return new AutoValue_HttpSenderConfig(
4244
endpoint,
4345
compressor,
@@ -49,7 +51,8 @@ public static HttpSenderConfig create(
4951
proxyOptions,
5052
retryPolicy,
5153
sslContext,
52-
trustManager);
54+
trustManager,
55+
executorService);
5356
}
5457

5558
public abstract String getEndpoint();
@@ -78,4 +81,7 @@ public static HttpSenderConfig create(
7881

7982
@Nullable
8083
public abstract X509TrustManager getTrustManager();
84+
85+
@Nullable
86+
public abstract ExecutorService getExecutorService();
8187
}

exporters/otlp/all/src/jmh/java/io/opentelemetry/exporter/otlp/trace/OltpExporterBenchmark.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public void setUp() {
8888
MarshalerTraceServiceGrpc.newFutureStub(defaultGrpcChannel, null),
8989
/* shutdownChannel= */ false,
9090
10,
91-
Collections::emptyMap),
91+
Collections::emptyMap,
92+
null),
9293
MeterProvider::noop);
9394

9495
okhttpGrpcSender =
@@ -105,6 +106,7 @@ public void setUp() {
105106
Collections::emptyMap,
106107
null,
107108
null,
109+
null,
108110
null),
109111
MeterProvider::noop);
110112

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.opentelemetry.sdk.common.export.RetryPolicy;
2222
import java.time.Duration;
2323
import java.util.Map;
24+
import java.util.concurrent.ExecutorService;
2425
import java.util.concurrent.TimeUnit;
2526
import java.util.function.Supplier;
2627
import javax.annotation.Nullable;
@@ -236,6 +237,19 @@ public OtlpHttpLogRecordExporterBuilder setServiceClassLoader(ClassLoader servic
236237
return this;
237238
}
238239

240+
/**
241+
* Set the {@link ExecutorService} used to execute requests.
242+
*
243+
* <p>NOTE: By calling this method, you are opting into managing the lifecycle of the {@code
244+
* executorService}. {@link ExecutorService#shutdown()} will NOT be called when this exporter is
245+
* shutdown.
246+
*/
247+
public OtlpHttpLogRecordExporterBuilder setExecutorService(ExecutorService executorService) {
248+
requireNonNull(executorService, "executorService");
249+
delegate.setExecutorService(executorService);
250+
return this;
251+
}
252+
239253
/**
240254
* Constructs a new instance of the exporter based on the builder's values.
241255
*

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.time.Duration;
2727
import java.util.Collection;
2828
import java.util.Map;
29+
import java.util.concurrent.ExecutorService;
2930
import java.util.concurrent.TimeUnit;
3031
import java.util.function.Supplier;
3132
import javax.annotation.Nullable;
@@ -264,6 +265,19 @@ public OtlpHttpMetricExporterBuilder setServiceClassLoader(ClassLoader serviceCl
264265
return this;
265266
}
266267

268+
/**
269+
* Set the {@link ExecutorService} used to execute requests.
270+
*
271+
* <p>NOTE: By calling this method, you are opting into managing the lifecycle of the {@code
272+
* executorService}. {@link ExecutorService#shutdown()} will NOT be called when this exporter is
273+
* shutdown.
274+
*/
275+
public OtlpHttpMetricExporterBuilder setExecutorService(ExecutorService executorService) {
276+
requireNonNull(executorService, "executorService");
277+
delegate.setExecutorService(executorService);
278+
return this;
279+
}
280+
267281
OtlpHttpMetricExporterBuilder exportAsJson() {
268282
delegate.exportAsJson();
269283
return this;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.opentelemetry.sdk.common.export.RetryPolicy;
2222
import java.time.Duration;
2323
import java.util.Map;
24+
import java.util.concurrent.ExecutorService;
2425
import java.util.concurrent.TimeUnit;
2526
import java.util.function.Supplier;
2627
import javax.annotation.Nullable;
@@ -237,6 +238,19 @@ public OtlpHttpSpanExporterBuilder setServiceClassLoader(ClassLoader serviceClas
237238
return this;
238239
}
239240

241+
/**
242+
* Set the {@link ExecutorService} used to execute requests.
243+
*
244+
* <p>NOTE: By calling this method, you are opting into managing the lifecycle of the {@code
245+
* executorService}. {@link ExecutorService#shutdown()} will NOT be called when this exporter is
246+
* shutdown.
247+
*/
248+
public OtlpHttpSpanExporterBuilder setExecutorService(ExecutorService executorService) {
249+
requireNonNull(executorService, "executorService");
250+
delegate.setExecutorService(executorService);
251+
return this;
252+
}
253+
240254
/**
241255
* Constructs a new instance of the exporter based on the builder's values.
242256
*

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.net.URI;
2323
import java.time.Duration;
2424
import java.util.Map;
25+
import java.util.concurrent.ExecutorService;
2526
import java.util.concurrent.TimeUnit;
2627
import java.util.function.Supplier;
2728
import javax.annotation.Nullable;
@@ -269,6 +270,19 @@ public OtlpGrpcLogRecordExporterBuilder setServiceClassLoader(ClassLoader servic
269270
return this;
270271
}
271272

273+
/**
274+
* Set the {@link ExecutorService} used to execute requests.
275+
*
276+
* <p>NOTE: By calling this method, you are opting into managing the lifecycle of the {@code
277+
* executorService}. {@link ExecutorService#shutdown()} will NOT be called when this exporter is
278+
* shutdown.
279+
*/
280+
public OtlpGrpcLogRecordExporterBuilder setExecutorService(ExecutorService executorService) {
281+
requireNonNull(executorService, "executorService");
282+
delegate.setExecutorService(executorService);
283+
return this;
284+
}
285+
272286
/**
273287
* Constructs a new instance of the exporter based on the builder's values.
274288
*

0 commit comments

Comments
 (0)