Skip to content

Commit c4412f2

Browse files
authored
Follow spec on span limits, batch processors (#7030)
1 parent 1c1d561 commit c4412f2

File tree

10 files changed

+49
-24
lines changed

10 files changed

+49
-24
lines changed

sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/TracerProviderConfigurationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void configureBatchSpanProcessor_configured() {
126126
Map<String, String> properties = new HashMap<>();
127127
properties.put("otel.bsp.schedule.delay", "100000");
128128
properties.put("otel.bsp.max.queue.size", "2");
129-
properties.put("otel.bsp.max.export.batch.size", "3");
129+
properties.put("otel.bsp.max.export.batch.size", "2");
130130
properties.put("otel.bsp.export.timeout", "4");
131131

132132
try (BatchSpanProcessor processor =
@@ -144,7 +144,7 @@ void configureBatchSpanProcessor_configured() {
144144
assertThat(worker)
145145
.extracting("exporterTimeoutNanos")
146146
.isEqualTo(TimeUnit.MILLISECONDS.toNanos(4));
147-
assertThat(worker).extracting("maxExportBatchSize").isEqualTo(3);
147+
assertThat(worker).extracting("maxExportBatchSize").isEqualTo(2);
148148
assertThat(worker)
149149
.extracting("queue")
150150
.isInstanceOfSatisfying(

sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/LoggerProviderConfigurationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void configureBatchLogRecordProcessor() {
118118
Map<String, String> properties = new HashMap<>();
119119
properties.put("otel.blrp.schedule.delay", "100000");
120120
properties.put("otel.blrp.max.queue.size", "2");
121-
properties.put("otel.blrp.max.export.batch.size", "3");
121+
properties.put("otel.blrp.max.export.batch.size", "2");
122122
properties.put("otel.blrp.export.timeout", "4");
123123

124124
try (BatchLogRecordProcessor processor =
@@ -136,7 +136,7 @@ void configureBatchLogRecordProcessor() {
136136
assertThat(worker)
137137
.extracting("exporterTimeoutNanos")
138138
.isEqualTo(TimeUnit.MILLISECONDS.toNanos(4));
139-
assertThat(worker).extracting("maxExportBatchSize").isEqualTo(3);
139+
assertThat(worker).extracting("maxExportBatchSize").isEqualTo(2);
140140
assertThat(worker)
141141
.extracting("queue")
142142
.isInstanceOfSatisfying(

sdk/logs/src/main/java/io/opentelemetry/sdk/logs/LogLimitsBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public final class LogLimitsBuilder {
3232
* @throws IllegalArgumentException if {@code maxNumberOfAttributes} is not positive.
3333
*/
3434
public LogLimitsBuilder setMaxNumberOfAttributes(int maxNumberOfAttributes) {
35-
Utils.checkArgument(maxNumberOfAttributes > 0, "maxNumberOfAttributes must be greater than 0");
35+
Utils.checkArgument(maxNumberOfAttributes >= 0, "maxNumberOfAttributes must be non-negative");
3636
this.maxNumAttributes = maxNumberOfAttributes;
3737
return this;
3838
}
@@ -48,7 +48,7 @@ public LogLimitsBuilder setMaxNumberOfAttributes(int maxNumberOfAttributes) {
4848
*/
4949
public LogLimitsBuilder setMaxAttributeValueLength(int maxAttributeValueLength) {
5050
Utils.checkArgument(
51-
maxAttributeValueLength > -1, "maxAttributeValueLength must be non-negative");
51+
maxAttributeValueLength >= 0, "maxAttributeValueLength must be non-negative");
5252
this.maxAttributeValueLength = maxAttributeValueLength;
5353
return this;
5454
}

sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessorBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ long getExporterTimeoutNanos() {
9898
* @param maxQueueSize the maximum number of Logs that are kept in the queue before start
9999
* dropping.
100100
* @return this.
101+
* @throws IllegalArgumentException if {@code maxQueueSize} is not positive.
101102
* @see BatchLogRecordProcessorBuilder#DEFAULT_MAX_QUEUE_SIZE
102103
*/
103104
public BatchLogRecordProcessorBuilder setMaxQueueSize(int maxQueueSize) {
105+
checkArgument(maxQueueSize > 0, "maxQueueSize must be positive.");
104106
this.maxQueueSize = maxQueueSize;
105107
return this;
106108
}

sdk/logs/src/test/java/io/opentelemetry/sdk/logs/LogLimitsTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.sdk.logs;
77

88
import static org.assertj.core.api.Assertions.assertThat;
9+
import static org.assertj.core.api.Assertions.assertThatCode;
910
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1011

1112
import org.junit.jupiter.api.Test;
@@ -33,11 +34,17 @@ void updateLogLimits_All() {
3334

3435
@Test
3536
void invalidLogLimits() {
36-
assertThatThrownBy(() -> LogLimits.builder().setMaxNumberOfAttributes(0))
37-
.isInstanceOf(IllegalArgumentException.class);
3837
assertThatThrownBy(() -> LogLimits.builder().setMaxNumberOfAttributes(-1))
3938
.isInstanceOf(IllegalArgumentException.class);
4039
assertThatThrownBy(() -> LogLimits.builder().setMaxAttributeValueLength(-1))
4140
.isInstanceOf(IllegalArgumentException.class);
4241
}
42+
43+
@Test
44+
void validLogLimits() {
45+
assertThatCode(() -> LogLimits.builder().setMaxNumberOfAttributes(0))
46+
.doesNotThrowAnyException();
47+
assertThatCode(() -> LogLimits.builder().setMaxAttributeValueLength(0))
48+
.doesNotThrowAnyException();
49+
}
4350
}

sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessorTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ void builderInvalidConfig() {
111111
() -> BatchLogRecordProcessor.builder(mockLogRecordExporter).setExporterTimeout(null))
112112
.isInstanceOf(NullPointerException.class)
113113
.hasMessage("timeout");
114+
assertThatThrownBy(
115+
() -> BatchLogRecordProcessor.builder(mockLogRecordExporter).setMaxQueueSize(0))
116+
.isInstanceOf(IllegalArgumentException.class)
117+
.hasMessage("maxQueueSize must be positive.");
114118
}
115119

116120
@Test
@@ -337,6 +341,7 @@ public void continuesIfExporterTimesOut() throws InterruptedException {
337341
.setExporterTimeout(exporterTimeoutMillis, TimeUnit.MILLISECONDS)
338342
.setScheduleDelay(1, TimeUnit.MILLISECONDS)
339343
.setMaxQueueSize(1)
344+
.setMaxExportBatchSize(1)
340345
.build();
341346
SdkLoggerProvider sdkLoggerProvider =
342347
SdkLoggerProvider.builder().addLogRecordProcessor(blp).build();

sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SpanLimitsBuilder.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public final class SpanLimitsBuilder {
3434
* @throws IllegalArgumentException if {@code maxNumberOfAttributes} is not positive.
3535
*/
3636
public SpanLimitsBuilder setMaxNumberOfAttributes(int maxNumberOfAttributes) {
37-
Utils.checkArgument(maxNumberOfAttributes > 0, "maxNumberOfAttributes must be greater than 0");
37+
Utils.checkArgument(maxNumberOfAttributes >= 0, "maxNumberOfAttributes must be non-negative");
3838
this.maxNumAttributes = maxNumberOfAttributes;
3939
return this;
4040
}
@@ -47,7 +47,7 @@ public SpanLimitsBuilder setMaxNumberOfAttributes(int maxNumberOfAttributes) {
4747
* @throws IllegalArgumentException if {@code maxNumberOfEvents} is not positive.
4848
*/
4949
public SpanLimitsBuilder setMaxNumberOfEvents(int maxNumberOfEvents) {
50-
Utils.checkArgument(maxNumberOfEvents > 0, "maxNumberOfEvents must be greater than 0");
50+
Utils.checkArgument(maxNumberOfEvents >= 0, "maxNumberOfEvents must be non-negative");
5151
this.maxNumEvents = maxNumberOfEvents;
5252
return this;
5353
}
@@ -60,7 +60,7 @@ public SpanLimitsBuilder setMaxNumberOfEvents(int maxNumberOfEvents) {
6060
* @throws IllegalArgumentException if {@code maxNumberOfLinks} is not positive.
6161
*/
6262
public SpanLimitsBuilder setMaxNumberOfLinks(int maxNumberOfLinks) {
63-
Utils.checkArgument(maxNumberOfLinks > 0, "maxNumberOfLinks must be greater than 0");
63+
Utils.checkArgument(maxNumberOfLinks >= 0, "maxNumberOfLinks must be non-negative");
6464
this.maxNumLinks = maxNumberOfLinks;
6565
return this;
6666
}
@@ -74,7 +74,7 @@ public SpanLimitsBuilder setMaxNumberOfLinks(int maxNumberOfLinks) {
7474
*/
7575
public SpanLimitsBuilder setMaxNumberOfAttributesPerEvent(int maxNumberOfAttributesPerEvent) {
7676
Utils.checkArgument(
77-
maxNumberOfAttributesPerEvent > 0, "maxNumberOfAttributesPerEvent must be greater than 0");
77+
maxNumberOfAttributesPerEvent >= 0, "maxNumberOfAttributesPerEvent must be non-negative");
7878
this.maxNumAttributesPerEvent = maxNumberOfAttributesPerEvent;
7979
return this;
8080
}
@@ -88,7 +88,7 @@ public SpanLimitsBuilder setMaxNumberOfAttributesPerEvent(int maxNumberOfAttribu
8888
*/
8989
public SpanLimitsBuilder setMaxNumberOfAttributesPerLink(int maxNumberOfAttributesPerLink) {
9090
Utils.checkArgument(
91-
maxNumberOfAttributesPerLink > 0, "maxNumberOfAttributesPerLink must be greater than 0");
91+
maxNumberOfAttributesPerLink >= 0, "maxNumberOfAttributesPerLink must be non-negative");
9292
this.maxNumAttributesPerLink = maxNumberOfAttributesPerLink;
9393
return this;
9494
}
@@ -104,7 +104,7 @@ public SpanLimitsBuilder setMaxNumberOfAttributesPerLink(int maxNumberOfAttribut
104104
*/
105105
public SpanLimitsBuilder setMaxAttributeValueLength(int maxAttributeValueLength) {
106106
Utils.checkArgument(
107-
maxAttributeValueLength > -1, "maxAttributeValueLength must be non-negative");
107+
maxAttributeValueLength >= 0, "maxAttributeValueLength must be non-negative");
108108
this.maxAttributeValueLength = maxAttributeValueLength;
109109
return this;
110110
}

sdk/trace/src/main/java/io/opentelemetry/sdk/trace/export/BatchSpanProcessorBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,11 @@ long getExporterTimeoutNanos() {
106106
* @param maxQueueSize the maximum number of Spans that are kept in the queue before start
107107
* dropping.
108108
* @return this.
109+
* @throws IllegalArgumentException if {@code maxQueueSize} is not positive.
109110
* @see BatchSpanProcessorBuilder#DEFAULT_MAX_QUEUE_SIZE
110111
*/
111112
public BatchSpanProcessorBuilder setMaxQueueSize(int maxQueueSize) {
113+
checkArgument(maxQueueSize > 0, "maxQueueSize must be positive.");
112114
this.maxQueueSize = maxQueueSize;
113115
return this;
114116
}

sdk/trace/src/test/java/io/opentelemetry/sdk/trace/config/SpanLimitsTest.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.sdk.trace.config;
77

88
import static org.assertj.core.api.Assertions.assertThat;
9+
import static org.assertj.core.api.Assertions.assertThatCode;
910
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1011

1112
import io.opentelemetry.sdk.trace.SpanLimits;
@@ -46,27 +47,31 @@ void updateSpanLimits_All() {
4647

4748
@Test
4849
void invalidSpanLimits() {
49-
assertThatThrownBy(() -> SpanLimits.builder().setMaxNumberOfAttributes(0))
50-
.isInstanceOf(IllegalArgumentException.class);
5150
assertThatThrownBy(() -> SpanLimits.builder().setMaxNumberOfAttributes(-1))
5251
.isInstanceOf(IllegalArgumentException.class);
53-
assertThatThrownBy(() -> SpanLimits.builder().setMaxNumberOfEvents(0))
54-
.isInstanceOf(IllegalArgumentException.class);
5552
assertThatThrownBy(() -> SpanLimits.builder().setMaxNumberOfEvents(-1))
5653
.isInstanceOf(IllegalArgumentException.class);
57-
assertThatThrownBy(() -> SpanLimits.builder().setMaxNumberOfLinks(0))
58-
.isInstanceOf(IllegalArgumentException.class);
5954
assertThatThrownBy(() -> SpanLimits.builder().setMaxNumberOfLinks(-1))
6055
.isInstanceOf(IllegalArgumentException.class);
61-
assertThatThrownBy(() -> SpanLimits.builder().setMaxNumberOfAttributesPerEvent(0))
62-
.isInstanceOf(IllegalArgumentException.class);
6356
assertThatThrownBy(() -> SpanLimits.builder().setMaxNumberOfAttributesPerEvent(-1))
6457
.isInstanceOf(IllegalArgumentException.class);
65-
assertThatThrownBy(() -> SpanLimits.builder().setMaxNumberOfAttributesPerLink(0))
66-
.isInstanceOf(IllegalArgumentException.class);
6758
assertThatThrownBy(() -> SpanLimits.builder().setMaxNumberOfAttributesPerLink(-1))
6859
.isInstanceOf(IllegalArgumentException.class);
6960
assertThatThrownBy(() -> SpanLimits.builder().setMaxAttributeValueLength(-1))
7061
.isInstanceOf(IllegalArgumentException.class);
7162
}
63+
64+
@Test
65+
void validSpanLimits() {
66+
assertThatCode(() -> SpanLimits.builder().setMaxNumberOfAttributes(0))
67+
.doesNotThrowAnyException();
68+
assertThatCode(() -> SpanLimits.builder().setMaxNumberOfEvents(0)).doesNotThrowAnyException();
69+
assertThatCode(() -> SpanLimits.builder().setMaxNumberOfLinks(0)).doesNotThrowAnyException();
70+
assertThatCode(() -> SpanLimits.builder().setMaxNumberOfAttributesPerEvent(0))
71+
.doesNotThrowAnyException();
72+
assertThatCode(() -> SpanLimits.builder().setMaxNumberOfAttributesPerLink(0))
73+
.doesNotThrowAnyException();
74+
assertThatCode(() -> SpanLimits.builder().setMaxAttributeValueLength(0))
75+
.doesNotThrowAnyException();
76+
}
7277
}

sdk/trace/src/test/java/io/opentelemetry/sdk/trace/export/BatchSpanProcessorTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ void builderInvalidConfig() {
121121
assertThatThrownBy(() -> BatchSpanProcessor.builder(mockSpanExporter).setExporterTimeout(null))
122122
.isInstanceOf(NullPointerException.class)
123123
.hasMessage("timeout");
124+
assertThatThrownBy(() -> BatchSpanProcessor.builder(mockSpanExporter).setMaxQueueSize(0))
125+
.isInstanceOf(IllegalArgumentException.class)
126+
.hasMessage("maxQueueSize must be positive.");
124127
}
125128

126129
@Test
@@ -419,6 +422,7 @@ public void continuesIfExporterTimesOut() throws InterruptedException {
419422
.setExporterTimeout(exporterTimeoutMillis, TimeUnit.MILLISECONDS)
420423
.setScheduleDelay(1, TimeUnit.MILLISECONDS)
421424
.setMaxQueueSize(1)
425+
.setMaxExportBatchSize(1)
422426
.build();
423427
sdkTracerProvider = SdkTracerProvider.builder().addSpanProcessor(bsp).build();
424428

0 commit comments

Comments
 (0)