Skip to content

Commit bb1a513

Browse files
committed
allow configuration of throttling rate and time unit
1 parent b2c476c commit bb1a513

File tree

16 files changed

+224
-10
lines changed

16 files changed

+224
-10
lines changed
Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
11
Comparing source compatibility of opentelemetry-exporter-otlp-1.54.0-SNAPSHOT.jar against opentelemetry-exporter-otlp-1.53.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 setThrottlingLoggerRate(double, double)
5+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder setThrottlingLoggerTimeUnit(java.util.concurrent.TimeUnit)
6+
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder (not serializable)
7+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
8+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder setThrottlingLoggerRate(double, double)
9+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder setThrottlingLoggerTimeUnit(java.util.concurrent.TimeUnit)
10+
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder (not serializable)
11+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
12+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder setThrottlingLoggerRate(double, double)
13+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder setThrottlingLoggerTimeUnit(java.util.concurrent.TimeUnit)
14+
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder (not serializable)
15+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
16+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder setThrottlingLoggerRate(double, double)
17+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder setThrottlingLoggerTimeUnit(java.util.concurrent.TimeUnit)
18+
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder (not serializable)
19+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
20+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder setThrottlingLoggerRate(double, double)
21+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder setThrottlingLoggerTimeUnit(java.util.concurrent.TimeUnit)
22+
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder (not serializable)
23+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
24+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder setThrottlingLoggerRate(double, double)
25+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder setThrottlingLoggerTimeUnit(java.util.concurrent.TimeUnit)

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.opentelemetry.sdk.common.InternalTelemetryVersion;
1717
import io.opentelemetry.sdk.internal.StandardComponentId;
1818
import io.opentelemetry.sdk.internal.ThrottlingLogger;
19+
import java.util.concurrent.TimeUnit;
1920
import java.util.concurrent.atomic.AtomicBoolean;
2021
import java.util.function.Supplier;
2122
import java.util.logging.Level;
@@ -32,7 +33,7 @@ public final class GrpcExporter<T extends Marshaler> {
3233

3334
private static final Logger internalLogger = Logger.getLogger(GrpcExporter.class.getName());
3435

35-
private final ThrottlingLogger logger = new ThrottlingLogger(internalLogger);
36+
private final ThrottlingLogger logger;
3637

3738
// We only log unimplemented once since it's a configuration issue that won't be recovered.
3839
private final AtomicBoolean loggedUnimplemented = new AtomicBoolean();
@@ -53,6 +54,24 @@ public GrpcExporter(
5354
this.exporterMetrics =
5455
new ExporterInstrumentation(
5556
internalTelemetryVersion, meterProviderSupplier, componentId, endpoint);
57+
this.logger = new ThrottlingLogger(internalLogger);
58+
}
59+
60+
public GrpcExporter(
61+
GrpcSender<T> grpcSender,
62+
InternalTelemetryVersion internalTelemetryVersion,
63+
StandardComponentId componentId,
64+
Supplier<MeterProvider> meterProviderSupplier,
65+
String endpoint,
66+
double rateLimit,
67+
double throttledRateLimit,
68+
TimeUnit rateTimeUnit) {
69+
this.type = componentId.getStandardType().signal().logFriendlyName();
70+
this.grpcSender = grpcSender;
71+
this.exporterMetrics =
72+
new ExporterInstrumentation(
73+
internalTelemetryVersion, meterProviderSupplier, componentId, endpoint);
74+
this.logger = new ThrottlingLogger(internalLogger, rateLimit, throttledRateLimit, rateTimeUnit);
5675
}
5776

5877
public CompletableResultCode export(T exportRequest, int numItems) {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public class GrpcExporterBuilder<T extends Marshaler> {
7676
// Use Object type since gRPC may not be on the classpath.
7777
@Nullable private Object grpcChannel;
7878

79+
private double throttlingLoggerRateLimit = 5;
80+
private double throttlingLoggerThrottledRateLimit = 1;
81+
private TimeUnit throttlingLoggerTimeUnit = TimeUnit.MINUTES;
82+
7983
public GrpcExporterBuilder(
8084
StandardComponentId.ExporterType exporterType,
8185
long defaultTimeoutSecs,
@@ -182,6 +186,17 @@ public GrpcExporterBuilder<T> setExecutorService(ExecutorService executorService
182186
return this;
183187
}
184188

189+
public GrpcExporterBuilder<T> setLogThrottlingRate(double rateLimit, double throttledRateLimit) {
190+
this.throttlingLoggerRateLimit = rateLimit;
191+
this.throttlingLoggerThrottledRateLimit = throttledRateLimit;
192+
return this;
193+
}
194+
195+
public GrpcExporterBuilder<T> setLogThrottlingTimeUnit(TimeUnit rateTimeUnit) {
196+
this.throttlingLoggerTimeUnit = rateTimeUnit;
197+
return this;
198+
}
199+
185200
@SuppressWarnings("BuilderReturnThis")
186201
public GrpcExporterBuilder<T> copy() {
187202
GrpcExporterBuilder<T> copy =
@@ -205,6 +220,9 @@ public GrpcExporterBuilder<T> copy() {
205220
copy.meterProviderSupplier = meterProviderSupplier;
206221
copy.internalTelemetryVersion = internalTelemetryVersion;
207222
copy.grpcChannel = grpcChannel;
223+
copy.throttlingLoggerRateLimit = throttlingLoggerRateLimit;
224+
copy.throttlingLoggerThrottledRateLimit = throttlingLoggerThrottledRateLimit;
225+
copy.throttlingLoggerTimeUnit = throttlingLoggerTimeUnit;
208226
return copy;
209227
}
210228

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.opentelemetry.sdk.internal.StandardComponentId;
1616
import io.opentelemetry.sdk.internal.ThrottlingLogger;
1717
import java.io.IOException;
18+
import java.util.concurrent.TimeUnit;
1819
import java.util.concurrent.atomic.AtomicBoolean;
1920
import java.util.function.Supplier;
2021
import java.util.logging.Level;
@@ -32,7 +33,7 @@ public final class HttpExporter<T extends Marshaler> {
3233

3334
private static final Logger internalLogger = Logger.getLogger(HttpExporter.class.getName());
3435

35-
private final ThrottlingLogger logger = new ThrottlingLogger(internalLogger);
36+
private final ThrottlingLogger logger;
3637
private final AtomicBoolean isShutdown = new AtomicBoolean();
3738

3839
private final String type;
@@ -50,6 +51,24 @@ public HttpExporter(
5051
this.exporterMetrics =
5152
new ExporterInstrumentation(
5253
internalTelemetryVersion, meterProviderSupplier, componentId, endpoint);
54+
this.logger = new ThrottlingLogger(internalLogger);
55+
}
56+
57+
public HttpExporter(
58+
StandardComponentId componentId,
59+
HttpSender httpSender,
60+
Supplier<MeterProvider> meterProviderSupplier,
61+
InternalTelemetryVersion internalTelemetryVersion,
62+
String endpoint,
63+
double rateLimit,
64+
double throttledRateLimit,
65+
TimeUnit rateTimeUnit) {
66+
this.type = componentId.getStandardType().signal().logFriendlyName();
67+
this.httpSender = httpSender;
68+
this.exporterMetrics =
69+
new ExporterInstrumentation(
70+
internalTelemetryVersion, meterProviderSupplier, componentId, endpoint);
71+
this.logger = new ThrottlingLogger(internalLogger, rateLimit, throttledRateLimit, rateTimeUnit);
5372
}
5473

5574
public CompletableResultCode export(T exportRequest, int numItems) {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public final class HttpExporterBuilder<T extends Marshaler> {
7070
ComponentLoader.forClassLoader(HttpExporterBuilder.class.getClassLoader());
7171
@Nullable private ExecutorService executorService;
7272

73+
private double throttlingLoggerRateLimit = 5;
74+
private double throttlingLoggerThrottledRateLimit = 1;
75+
private TimeUnit throttlingLoggerTimeUnit = TimeUnit.MINUTES;
76+
7377
public HttpExporterBuilder(
7478
StandardComponentId.ExporterType exporterType, String defaultEndpoint) {
7579
this.exporterType = exporterType;
@@ -187,6 +191,17 @@ private static StandardComponentId.ExporterType mapToJsonTypeIfPossible(
187191
}
188192
}
189193

194+
public HttpExporterBuilder<T> setLogThrottlingRate(double rateLimit, double throttledRateLimit) {
195+
this.throttlingLoggerRateLimit = rateLimit;
196+
this.throttlingLoggerThrottledRateLimit = throttledRateLimit;
197+
return this;
198+
}
199+
200+
public HttpExporterBuilder<T> setLogThrottlingTimeUnit(TimeUnit rateTimeUnit) {
201+
this.throttlingLoggerTimeUnit = rateTimeUnit;
202+
return this;
203+
}
204+
190205
@SuppressWarnings("BuilderReturnThis")
191206
public HttpExporterBuilder<T> copy() {
192207
HttpExporterBuilder<T> copy = new HttpExporterBuilder<>(exporterType, endpoint);
@@ -204,6 +219,9 @@ public HttpExporterBuilder<T> copy() {
204219
copy.meterProviderSupplier = meterProviderSupplier;
205220
copy.internalTelemetryVersion = internalTelemetryVersion;
206221
copy.proxyOptions = proxyOptions;
222+
copy.throttlingLoggerRateLimit = throttlingLoggerRateLimit;
223+
copy.throttlingLoggerThrottledRateLimit = throttlingLoggerThrottledRateLimit;
224+
copy.throttlingLoggerTimeUnit = throttlingLoggerTimeUnit;
207225
return copy;
208226
}
209227

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,19 @@ public OtlpHttpLogRecordExporterBuilder setExecutorService(ExecutorService execu
275275
return this;
276276
}
277277

278+
/** Set the initial and throttled rate for the ThrottlingLogger. */
279+
public OtlpHttpLogRecordExporterBuilder setThrottlingLoggerRate(
280+
double rateLimit, double throttledRateLimit) {
281+
delegate.setLogThrottlingRate(rateLimit, throttledRateLimit);
282+
return this;
283+
}
284+
285+
/** Set the time unit used for the ThrottlingLogger. */
286+
public OtlpHttpLogRecordExporterBuilder setThrottlingLoggerTimeUnit(TimeUnit rateTimeUnit) {
287+
delegate.setLogThrottlingTimeUnit(rateTimeUnit);
288+
return this;
289+
}
290+
278291
/**
279292
* Constructs a new instance of the exporter based on the builder's values.
280293
*

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,19 @@ OtlpHttpMetricExporterBuilder exportAsJson() {
339339
return this;
340340
}
341341

342+
/** Set the initial and throttled rate for the ThrottlingLogger. */
343+
public OtlpHttpMetricExporterBuilder setThrottlingLoggerRate(
344+
double rateLimit, double throttledRateLimit) {
345+
delegate.setLogThrottlingRate(rateLimit, throttledRateLimit);
346+
return this;
347+
}
348+
349+
/** Set the time unit used for the ThrottlingLogger. */
350+
public OtlpHttpMetricExporterBuilder setThrottlingLoggerTimeUnit(TimeUnit rateTimeUnit) {
351+
delegate.setLogThrottlingTimeUnit(rateTimeUnit);
352+
return this;
353+
}
354+
342355
/**
343356
* Constructs a new instance of the exporter based on the builder's values.
344357
*

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,19 @@ public OtlpHttpSpanExporterBuilder setExecutorService(ExecutorService executorSe
276276
return this;
277277
}
278278

279+
/** Set the initial and throttled rate for the ThrottlingLogger. */
280+
public OtlpHttpSpanExporterBuilder setThrottlingLoggerRate(
281+
double rateLimit, double throttledRateLimit) {
282+
delegate.setLogThrottlingRate(rateLimit, throttledRateLimit);
283+
return this;
284+
}
285+
286+
/** Set the time unit used for the ThrottlingLogger. */
287+
public OtlpHttpSpanExporterBuilder setThrottlingLoggerTimeUnit(TimeUnit rateTimeUnit) {
288+
delegate.setLogThrottlingTimeUnit(rateTimeUnit);
289+
return this;
290+
}
291+
279292
/**
280293
* Constructs a new instance of the exporter based on the builder's values.
281294
*

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import java.net.URLDecoder;
2020
import java.nio.charset.StandardCharsets;
2121
import java.time.Duration;
22+
import java.util.Locale;
2223
import java.util.Map;
24+
import java.util.concurrent.TimeUnit;
2325
import java.util.function.BiConsumer;
2426
import java.util.function.Consumer;
2527
import java.util.logging.Logger;
@@ -62,7 +64,9 @@ public static void configureOtlpExporterBuilder(
6264
Consumer<byte[]> setTrustedCertificates,
6365
BiConsumer<byte[], byte[]> setClientTls,
6466
Consumer<RetryPolicy> setRetryPolicy,
65-
Consumer<MemoryMode> setMemoryMode) {
67+
Consumer<MemoryMode> setMemoryMode,
68+
BiConsumer<Double, Double> setThrottlingLoggerRate,
69+
Consumer<TimeUnit> setThrottlingLoggerTimeUnit) {
6670
setComponentLoader.accept(config.getComponentLoader());
6771

6872
String protocol = getOtlpProtocol(dataType, config);
@@ -143,6 +147,27 @@ public static void configureOtlpExporterBuilder(
143147
}
144148

145149
ExporterBuilderUtil.configureExporterMemoryMode(config, setMemoryMode);
150+
151+
double logRateStr = config.getDouble("otel.exporter.otlp.lograte", 5);
152+
double logThrottleRateStr = config.getDouble("otel.exporter.otlp.throttledlograte", 1);
153+
setThrottlingLoggerRate.accept(logRateStr, logThrottleRateStr);
154+
155+
String logTimeUnitStr = config.getString("otel.exporter.otlp.logtimeunit", "MINUTES");
156+
TimeUnit logTimeUnit;
157+
switch (logTimeUnitStr.toUpperCase(Locale.ROOT)) {
158+
case "SECONDS":
159+
logTimeUnit = TimeUnit.SECONDS;
160+
break;
161+
case "HOURS":
162+
logTimeUnit = TimeUnit.HOURS;
163+
break;
164+
case "DAYS":
165+
logTimeUnit = TimeUnit.DAYS;
166+
break;
167+
default:
168+
logTimeUnit = TimeUnit.MINUTES;
169+
}
170+
setThrottlingLoggerTimeUnit.accept(logTimeUnit);
146171
}
147172

148173
static void configureOtlpHeaders(

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public LogRecordExporter createExporter(ConfigProperties config) {
5353
builder::setTrustedCertificates,
5454
builder::setClientTls,
5555
builder::setRetryPolicy,
56-
builder::setMemoryMode);
56+
builder::setMemoryMode,
57+
builder::setThrottlingLoggerRate,
58+
builder::setThrottlingLoggerTimeUnit);
5759
builder.setMeterProvider(meterProviderRef::get);
5860

5961
return builder.build();
@@ -71,7 +73,9 @@ public LogRecordExporter createExporter(ConfigProperties config) {
7173
builder::setTrustedCertificates,
7274
builder::setClientTls,
7375
builder::setRetryPolicy,
74-
builder::setMemoryMode);
76+
builder::setMemoryMode,
77+
builder::setThrottlingLoggerRate,
78+
builder::setThrottlingLoggerTimeUnit);
7579
builder.setMeterProvider(meterProviderRef::get);
7680

7781
return builder.build();

0 commit comments

Comments
 (0)