Skip to content

Commit 99d30c5

Browse files
committed
first pass
1 parent 807b0b1 commit 99d30c5

74 files changed

Lines changed: 536 additions & 24 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/all/src/main/java/io/opentelemetry/api/GlobalOpenTelemetry.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public static OpenTelemetry get() {
169169
* OpenTelemetrySdk.builder().buildAndRegisterGlobal()} instead of calling this method directly.
170170
*/
171171
public static void set(OpenTelemetry openTelemetry) {
172+
Objects.requireNonNull(openTelemetry, "openTelemetry");
172173
synchronized (mutex) {
173174
if (globalOpenTelemetry != null) {
174175
throw new IllegalStateException(
@@ -192,6 +193,7 @@ public static void set(OpenTelemetry openTelemetry) {
192193
* @since 1.52.0
193194
*/
194195
public static void set(Supplier<OpenTelemetry> supplier) {
196+
Objects.requireNonNull(supplier, "supplier");
195197
synchronized (mutex) {
196198
OpenTelemetry openTelemetry = supplier.get();
197199
set(openTelemetry);
@@ -386,6 +388,7 @@ public ContextPropagators getPropagators() {
386388

387389
@Override
388390
public TracerBuilder tracerBuilder(String instrumentationScopeName) {
391+
Objects.requireNonNull(instrumentationScopeName, "instrumentationScopeName");
389392
return delegate.tracerBuilder(instrumentationScopeName);
390393
}
391394
}

api/all/src/main/java/io/opentelemetry/api/logs/DefaultLogger.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import io.opentelemetry.api.common.AttributeKey;
99
import io.opentelemetry.api.common.Value;
10+
import io.opentelemetry.common.ApiUsageLogger;
1011
import io.opentelemetry.context.Context;
1112
import java.time.Instant;
1213
import java.util.concurrent.TimeUnit;
@@ -59,26 +60,46 @@ public LogRecordBuilder setObservedTimestamp(Instant instant) {
5960

6061
@Override
6162
public LogRecordBuilder setContext(Context context) {
63+
if (context == null) {
64+
ApiUsageLogger.logNullParam(LogRecordBuilder.class, "setContext", "context");
65+
return this;
66+
}
6267
return this;
6368
}
6469

6570
@Override
6671
public LogRecordBuilder setSeverity(Severity severity) {
72+
if (severity == null) {
73+
ApiUsageLogger.logNullParam(LogRecordBuilder.class, "setSeverity", "severity");
74+
return this;
75+
}
6776
return this;
6877
}
6978

7079
@Override
7180
public LogRecordBuilder setSeverityText(String severityText) {
81+
if (severityText == null) {
82+
ApiUsageLogger.logNullParam(LogRecordBuilder.class, "setSeverityText", "severityText");
83+
return this;
84+
}
7285
return this;
7386
}
7487

7588
@Override
7689
public LogRecordBuilder setBody(String body) {
90+
if (body == null) {
91+
ApiUsageLogger.logNullParam(LogRecordBuilder.class, "setBody", "body");
92+
return this;
93+
}
7794
return this;
7895
}
7996

8097
@Override
8198
public LogRecordBuilder setBody(Value<?> body) {
99+
if (body == null) {
100+
ApiUsageLogger.logNullParam(LogRecordBuilder.class, "setBody", "body");
101+
return this;
102+
}
82103
return this;
83104
}
84105

api/all/src/main/java/io/opentelemetry/api/logs/DefaultLoggerProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package io.opentelemetry.api.logs;
77

8+
import java.util.Objects;
9+
810
class DefaultLoggerProvider implements LoggerProvider {
911

1012
private static final LoggerProvider INSTANCE = new DefaultLoggerProvider();
@@ -18,18 +20,21 @@ static LoggerProvider getInstance() {
1820

1921
@Override
2022
public LoggerBuilder loggerBuilder(String instrumentationScopeName) {
23+
Objects.requireNonNull(instrumentationScopeName, "instrumentationScopeName");
2124
return NOOP_BUILDER;
2225
}
2326

2427
private static class NoopLoggerBuilder implements LoggerBuilder {
2528

2629
@Override
2730
public LoggerBuilder setSchemaUrl(String schemaUrl) {
31+
Objects.requireNonNull(schemaUrl, "schemaUrl");
2832
return this;
2933
}
3034

3135
@Override
3236
public LoggerBuilder setInstrumentationVersion(String instrumentationVersion) {
37+
Objects.requireNonNull(instrumentationVersion, "instrumentationVersion");
3338
return this;
3439
}
3540

api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java

Lines changed: 120 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
package io.opentelemetry.api.metrics;
77

88
import io.opentelemetry.api.common.Attributes;
9+
import io.opentelemetry.common.ApiUsageLogger;
910
import io.opentelemetry.context.Context;
11+
import java.util.Objects;
1012
import java.util.function.Consumer;
1113
import javax.annotation.concurrent.ThreadSafe;
1214

@@ -38,21 +40,25 @@ static Meter getInstance() {
3840

3941
@Override
4042
public LongCounterBuilder counterBuilder(String name) {
43+
Objects.requireNonNull(name, "name");
4144
return NOOP_LONG_COUNTER_BUILDER;
4245
}
4346

4447
@Override
4548
public LongUpDownCounterBuilder upDownCounterBuilder(String name) {
49+
Objects.requireNonNull(name, "name");
4650
return NOOP_LONG_UP_DOWN_COUNTER_BUILDER;
4751
}
4852

4953
@Override
5054
public DoubleHistogramBuilder histogramBuilder(String name) {
55+
Objects.requireNonNull(name, "name");
5156
return NOOP_DOUBLE_HISTOGRAM_BUILDER;
5257
}
5358

5459
@Override
5560
public DoubleGaugeBuilder gaugeBuilder(String name) {
61+
Objects.requireNonNull(name, "name");
5662
return NOOP_DOUBLE_GAUGE_BUILDER;
5763
}
5864

@@ -73,10 +79,21 @@ public boolean isEnabled() {
7379
}
7480

7581
@Override
76-
public void add(long value, Attributes attributes, Context context) {}
82+
public void add(long value, Attributes attributes, Context context) {
83+
if (attributes == null) {
84+
ApiUsageLogger.logNullParam(LongCounter.class, "add", "attributes");
85+
}
86+
if (context == null) {
87+
ApiUsageLogger.logNullParam(LongCounter.class, "add", "context");
88+
}
89+
}
7790

7891
@Override
79-
public void add(long value, Attributes attributes) {}
92+
public void add(long value, Attributes attributes) {
93+
if (attributes == null) {
94+
ApiUsageLogger.logNullParam(LongCounter.class, "add", "attributes");
95+
}
96+
}
8097

8198
@Override
8299
public void add(long value) {}
@@ -89,10 +106,21 @@ public boolean isEnabled() {
89106
}
90107

91108
@Override
92-
public void add(double value, Attributes attributes, Context context) {}
109+
public void add(double value, Attributes attributes, Context context) {
110+
if (attributes == null) {
111+
ApiUsageLogger.logNullParam(DoubleCounter.class, "add", "attributes");
112+
}
113+
if (context == null) {
114+
ApiUsageLogger.logNullParam(DoubleCounter.class, "add", "context");
115+
}
116+
}
93117

94118
@Override
95-
public void add(double value, Attributes attributes) {}
119+
public void add(double value, Attributes attributes) {
120+
if (attributes == null) {
121+
ApiUsageLogger.logNullParam(DoubleCounter.class, "add", "attributes");
122+
}
123+
}
96124

97125
@Override
98126
public void add(double value) {}
@@ -175,10 +203,21 @@ public boolean isEnabled() {
175203
}
176204

177205
@Override
178-
public void add(long value, Attributes attributes, Context context) {}
206+
public void add(long value, Attributes attributes, Context context) {
207+
if (attributes == null) {
208+
ApiUsageLogger.logNullParam(LongUpDownCounter.class, "add", "attributes");
209+
}
210+
if (context == null) {
211+
ApiUsageLogger.logNullParam(LongUpDownCounter.class, "add", "context");
212+
}
213+
}
179214

180215
@Override
181-
public void add(long value, Attributes attributes) {}
216+
public void add(long value, Attributes attributes) {
217+
if (attributes == null) {
218+
ApiUsageLogger.logNullParam(LongUpDownCounter.class, "add", "attributes");
219+
}
220+
}
182221

183222
@Override
184223
public void add(long value) {}
@@ -191,10 +230,21 @@ public boolean isEnabled() {
191230
}
192231

193232
@Override
194-
public void add(double value, Attributes attributes, Context context) {}
233+
public void add(double value, Attributes attributes, Context context) {
234+
if (attributes == null) {
235+
ApiUsageLogger.logNullParam(DoubleUpDownCounter.class, "add", "attributes");
236+
}
237+
if (context == null) {
238+
ApiUsageLogger.logNullParam(DoubleUpDownCounter.class, "add", "context");
239+
}
240+
}
195241

196242
@Override
197-
public void add(double value, Attributes attributes) {}
243+
public void add(double value, Attributes attributes) {
244+
if (attributes == null) {
245+
ApiUsageLogger.logNullParam(DoubleUpDownCounter.class, "add", "attributes");
246+
}
247+
}
198248

199249
@Override
200250
public void add(double value) {}
@@ -279,10 +329,21 @@ public boolean isEnabled() {
279329
}
280330

281331
@Override
282-
public void record(double value, Attributes attributes, Context context) {}
332+
public void record(double value, Attributes attributes, Context context) {
333+
if (attributes == null) {
334+
ApiUsageLogger.logNullParam(DoubleHistogram.class, "record", "attributes");
335+
}
336+
if (context == null) {
337+
ApiUsageLogger.logNullParam(DoubleHistogram.class, "record", "context");
338+
}
339+
}
283340

284341
@Override
285-
public void record(double value, Attributes attributes) {}
342+
public void record(double value, Attributes attributes) {
343+
if (attributes == null) {
344+
ApiUsageLogger.logNullParam(DoubleHistogram.class, "record", "attributes");
345+
}
346+
}
286347

287348
@Override
288349
public void record(double value) {}
@@ -295,10 +356,21 @@ public boolean isEnabled() {
295356
}
296357

297358
@Override
298-
public void record(long value, Attributes attributes, Context context) {}
359+
public void record(long value, Attributes attributes, Context context) {
360+
if (attributes == null) {
361+
ApiUsageLogger.logNullParam(LongHistogram.class, "record", "attributes");
362+
}
363+
if (context == null) {
364+
ApiUsageLogger.logNullParam(LongHistogram.class, "record", "context");
365+
}
366+
}
299367

300368
@Override
301-
public void record(long value, Attributes attributes) {}
369+
public void record(long value, Attributes attributes) {
370+
if (attributes == null) {
371+
ApiUsageLogger.logNullParam(LongHistogram.class, "record", "attributes");
372+
}
373+
}
302374

303375
@Override
304376
public void record(long value) {}
@@ -396,10 +468,21 @@ public boolean isEnabled() {
396468
public void set(double value) {}
397469

398470
@Override
399-
public void set(double value, Attributes attributes) {}
471+
public void set(double value, Attributes attributes) {
472+
if (attributes == null) {
473+
ApiUsageLogger.logNullParam(DoubleGauge.class, "set", "attributes");
474+
}
475+
}
400476

401477
@Override
402-
public void set(double value, Attributes attributes, Context context) {}
478+
public void set(double value, Attributes attributes, Context context) {
479+
if (attributes == null) {
480+
ApiUsageLogger.logNullParam(DoubleGauge.class, "set", "attributes");
481+
}
482+
if (context == null) {
483+
ApiUsageLogger.logNullParam(DoubleGauge.class, "set", "context");
484+
}
485+
}
403486
}
404487

405488
private static class NoopLongGaugeBuilder implements LongGaugeBuilder {
@@ -442,25 +525,44 @@ public boolean isEnabled() {
442525
public void set(long value) {}
443526

444527
@Override
445-
public void set(long value, Attributes attributes) {}
528+
public void set(long value, Attributes attributes) {
529+
if (attributes == null) {
530+
ApiUsageLogger.logNullParam(LongGauge.class, "set", "attributes");
531+
}
532+
}
446533

447534
@Override
448-
public void set(long value, Attributes attributes, Context context) {}
535+
public void set(long value, Attributes attributes, Context context) {
536+
if (attributes == null) {
537+
ApiUsageLogger.logNullParam(LongGauge.class, "set", "attributes");
538+
}
539+
if (context == null) {
540+
ApiUsageLogger.logNullParam(LongGauge.class, "set", "context");
541+
}
542+
}
449543
}
450544

451545
private static class NoopObservableDoubleMeasurement implements ObservableDoubleMeasurement {
452546
@Override
453547
public void record(double value) {}
454548

455549
@Override
456-
public void record(double value, Attributes attributes) {}
550+
public void record(double value, Attributes attributes) {
551+
if (attributes == null) {
552+
ApiUsageLogger.logNullParam(ObservableDoubleMeasurement.class, "record", "attributes");
553+
}
554+
}
457555
}
458556

459557
private static class NoopObservableLongMeasurement implements ObservableLongMeasurement {
460558
@Override
461559
public void record(long value) {}
462560

463561
@Override
464-
public void record(long value, Attributes attributes) {}
562+
public void record(long value, Attributes attributes) {
563+
if (attributes == null) {
564+
ApiUsageLogger.logNullParam(ObservableLongMeasurement.class, "record", "attributes");
565+
}
566+
}
465567
}
466568
}

api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeterProvider.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
package io.opentelemetry.api.metrics;
77

88
import io.opentelemetry.api.internal.IncubatingUtil;
9+
import java.util.Objects;
910

1011
/** A {@link MeterProvider} that does nothing. */
1112
class DefaultMeterProvider implements MeterProvider {
1213
@Override
1314
public MeterBuilder meterBuilder(String instrumentationScopeName) {
15+
Objects.requireNonNull(instrumentationScopeName, "instrumentationScopeName");
1416
return BUILDER_INSTANCE;
1517
}
1618

@@ -30,11 +32,13 @@ private static class NoopMeterBuilder implements MeterBuilder {
3032

3133
@Override
3234
public MeterBuilder setSchemaUrl(String schemaUrl) {
35+
Objects.requireNonNull(schemaUrl, "schemaUrl");
3336
return this;
3437
}
3538

3639
@Override
3740
public MeterBuilder setInstrumentationVersion(String instrumentationScopeVersion) {
41+
Objects.requireNonNull(instrumentationScopeVersion, "instrumentationScopeVersion");
3842
return this;
3943
}
4044

0 commit comments

Comments
 (0)