Skip to content

Commit 8509675

Browse files
committed
add declarative config for log throttling
1 parent c67641c commit 8509675

18 files changed

Lines changed: 222 additions & 5 deletions
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.57.0-SNAPSHOT.jar against opentelemetry-exporter-otlp-1.56.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 setLogThrottlingRate(double, double)
5+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder setLogThrottlingTimeUnit(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 setLogThrottlingRate(double, double)
9+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder setLogThrottlingTimeUnit(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 setLogThrottlingRate(double, double)
13+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder setLogThrottlingTimeUnit(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 setLogThrottlingRate(double, double)
17+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder setLogThrottlingTimeUnit(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 setLogThrottlingRate(double, double)
21+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder setLogThrottlingTimeUnit(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 setLogThrottlingRate(double, double)
25+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder setLogThrottlingTimeUnit(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: 22 additions & 1 deletion
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 =
@@ -206,6 +221,9 @@ public GrpcExporterBuilder<T> copy() {
206221
copy.internalTelemetryVersion = internalTelemetryVersion;
207222
copy.grpcChannel = grpcChannel;
208223
copy.componentLoader = componentLoader;
224+
copy.throttlingLoggerRateLimit = throttlingLoggerRateLimit;
225+
copy.throttlingLoggerThrottledRateLimit = throttlingLoggerThrottledRateLimit;
226+
copy.throttlingLoggerTimeUnit = throttlingLoggerTimeUnit;
209227
return copy;
210228
}
211229

@@ -255,7 +273,10 @@ public GrpcExporter<T> build() {
255273
internalTelemetryVersion,
256274
ComponentId.generateLazy(exporterType),
257275
meterProviderSupplier,
258-
endpoint.toString());
276+
endpoint.toString(),
277+
throttlingLoggerRateLimit,
278+
throttlingLoggerThrottledRateLimit,
279+
throttlingLoggerTimeUnit);
259280
}
260281

261282
public String toString(boolean includePrefixAndSuffix) {

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: 22 additions & 1 deletion
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;
@@ -167,6 +171,17 @@ public HttpExporterBuilder<T> setExecutorService(ExecutorService executorService
167171
return this;
168172
}
169173

174+
public HttpExporterBuilder<T> setLogThrottlingRate(double rateLimit, double throttledRateLimit) {
175+
this.throttlingLoggerRateLimit = rateLimit;
176+
this.throttlingLoggerThrottledRateLimit = throttledRateLimit;
177+
return this;
178+
}
179+
180+
public HttpExporterBuilder<T> setLogThrottlingTimeUnit(TimeUnit rateTimeUnit) {
181+
this.throttlingLoggerTimeUnit = rateTimeUnit;
182+
return this;
183+
}
184+
170185
public HttpExporterBuilder<T> exportAsJson() {
171186
this.exportAsJson = true;
172187
exporterType = mapToJsonTypeIfPossible(exporterType);
@@ -205,6 +220,9 @@ public HttpExporterBuilder<T> copy() {
205220
copy.internalTelemetryVersion = internalTelemetryVersion;
206221
copy.proxyOptions = proxyOptions;
207222
copy.componentLoader = componentLoader;
223+
copy.throttlingLoggerRateLimit = throttlingLoggerRateLimit;
224+
copy.throttlingLoggerThrottledRateLimit = throttlingLoggerThrottledRateLimit;
225+
copy.throttlingLoggerTimeUnit = throttlingLoggerTimeUnit;
208226
return copy;
209227
}
210228

@@ -254,7 +272,10 @@ public HttpExporter<T> build() {
254272
httpSender,
255273
meterProviderSupplier,
256274
internalTelemetryVersion,
257-
endpoint);
275+
endpoint,
276+
throttlingLoggerRateLimit,
277+
throttlingLoggerThrottledRateLimit,
278+
throttlingLoggerTimeUnit);
258279
}
259280

260281
public String toString(boolean includePrefixAndSuffix) {

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
@@ -275,6 +275,20 @@ public OtlpHttpLogRecordExporterBuilder setExecutorService(ExecutorService execu
275275
return this;
276276
}
277277

278+
public OtlpHttpLogRecordExporterBuilder setLogThrottlingRate(
279+
double rateLimit, double throttledRateLimit) {
280+
checkArgument(rateLimit > 0, "rateLimit invalid");
281+
checkArgument(throttledRateLimit > 0, "throttledRateLimit invalid");
282+
delegate.setLogThrottlingRate(rateLimit, throttledRateLimit);
283+
return this;
284+
}
285+
286+
public OtlpHttpLogRecordExporterBuilder setLogThrottlingTimeUnit(TimeUnit timeUnit) {
287+
requireNonNull(timeUnit, "logTimeUnit");
288+
delegate.setLogThrottlingTimeUnit(timeUnit);
289+
return this;
290+
}
291+
278292
/**
279293
* Constructs a new instance of the exporter based on the builder's values.
280294
*

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
@@ -334,6 +334,20 @@ public OtlpHttpMetricExporterBuilder setExecutorService(ExecutorService executor
334334
return this;
335335
}
336336

337+
public OtlpHttpMetricExporterBuilder setLogThrottlingRate(
338+
double rateLimit, double throttledRateLimit) {
339+
checkArgument(rateLimit > 0, "rateLimit invalid");
340+
checkArgument(throttledRateLimit > 0, "throttledRateLimit invalid");
341+
delegate.setLogThrottlingRate(rateLimit, throttledRateLimit);
342+
return this;
343+
}
344+
345+
public OtlpHttpMetricExporterBuilder setLogThrottlingTimeUnit(TimeUnit timeUnit) {
346+
requireNonNull(timeUnit, "logTimeUnit");
347+
delegate.setLogThrottlingTimeUnit(timeUnit);
348+
return this;
349+
}
350+
337351
OtlpHttpMetricExporterBuilder exportAsJson() {
338352
delegate.exportAsJson();
339353
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
@@ -276,6 +276,20 @@ public OtlpHttpSpanExporterBuilder setExecutorService(ExecutorService executorSe
276276
return this;
277277
}
278278

279+
public OtlpHttpSpanExporterBuilder setLogThrottlingRate(
280+
double rateLimit, double throttledRateLimit) {
281+
checkArgument(rateLimit > 0, "rateLimit invalid");
282+
checkArgument(throttledRateLimit > 0, "throttledRateLimit invalid");
283+
delegate.setLogThrottlingRate(rateLimit, throttledRateLimit);
284+
return this;
285+
}
286+
287+
public OtlpHttpSpanExporterBuilder setLogThrottlingTimeUnit(TimeUnit timeUnit) {
288+
requireNonNull(timeUnit, "logTimeUnit");
289+
delegate.setLogThrottlingTimeUnit(timeUnit);
290+
return this;
291+
}
292+
279293
/**
280294
* Constructs a new instance of the exporter based on the builder's values.
281295
*

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.time.Duration;
2323
import java.util.Collections;
2424
import java.util.List;
25+
import java.util.Locale;
26+
import java.util.concurrent.TimeUnit;
2527
import java.util.function.BiConsumer;
2628
import java.util.function.Consumer;
2729

@@ -57,6 +59,8 @@ public static void configureOtlpExporterBuilder(
5759
BiConsumer<byte[], byte[]> setClientTls,
5860
Consumer<RetryPolicy> setRetryPolicy,
5961
Consumer<MemoryMode> setMemoryMode,
62+
BiConsumer<Double, Double> setLogThrottlingRate,
63+
Consumer<TimeUnit> setLogTimeUnit,
6064
boolean isHttpProtobuf) {
6165
setComponentLoader.accept(config.getComponentLoader());
6266

@@ -117,6 +121,20 @@ public static void configureOtlpExporterBuilder(
117121
}
118122

119123
IncubatingExporterBuilderUtil.configureExporterMemoryMode(config, setMemoryMode);
124+
125+
Double throttlingLoggerRateLimit = config.getDouble("log_rate");
126+
Double throttlingLoggerThrottledRateLimit = config.getDouble("throttled_log_rate");
127+
128+
if (throttlingLoggerRateLimit != null && throttlingLoggerThrottledRateLimit != null) {
129+
setLogThrottlingRate.accept(throttlingLoggerRateLimit, throttlingLoggerThrottledRateLimit);
130+
}
131+
132+
String throttlingLoggerTimeUnitStr = config.getString("log_rate_unit");
133+
if (throttlingLoggerTimeUnitStr != null) {
134+
TimeUnit throttlingLoggerTimeUnit =
135+
TimeUnit.valueOf(throttlingLoggerTimeUnitStr.toUpperCase(Locale.ROOT));
136+
setLogTimeUnit.accept(throttlingLoggerTimeUnit);
137+
}
120138
}
121139

122140
private OtlpDeclarativeConfigUtil() {}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public LogRecordExporter create(DeclarativeConfigProperties config) {
4747
builder::setClientTls,
4848
builder::setRetryPolicy,
4949
builder::setMemoryMode,
50+
builder::setLogThrottlingRate,
51+
builder::setLogThrottlingTimeUnit,
5052
/* isHttpProtobuf= */ false);
5153

5254
return builder.build();

0 commit comments

Comments
 (0)