Skip to content

Commit f7c5ada

Browse files
committed
Promote Extended{Type}{Instrument}#isEnabled to stable API
1 parent f575be1 commit f7c5ada

36 files changed

Lines changed: 242 additions & 169 deletions

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ public BatchCallback batchCallback(
6767
private DefaultMeter() {}
6868

6969
private static class NoopLongCounter implements LongCounter {
70+
@Override
71+
public boolean isEnabled() {
72+
return false;
73+
}
74+
7075
@Override
7176
public void add(long value, Attributes attributes, Context context) {}
7277

@@ -78,6 +83,11 @@ public void add(long value) {}
7883
}
7984

8085
private static class NoopDoubleCounter implements DoubleCounter {
86+
@Override
87+
public boolean isEnabled() {
88+
return false;
89+
}
90+
8191
@Override
8292
public void add(double value, Attributes attributes, Context context) {}
8393

@@ -159,6 +169,11 @@ public ObservableDoubleMeasurement buildObserver() {
159169
}
160170

161171
private static class NoopLongUpDownCounter implements LongUpDownCounter {
172+
@Override
173+
public boolean isEnabled() {
174+
return false;
175+
}
176+
162177
@Override
163178
public void add(long value, Attributes attributes, Context context) {}
164179

@@ -170,6 +185,11 @@ public void add(long value) {}
170185
}
171186

172187
private static class NoopDoubleUpDownCounter implements DoubleUpDownCounter {
188+
@Override
189+
public boolean isEnabled() {
190+
return false;
191+
}
192+
173193
@Override
174194
public void add(double value, Attributes attributes, Context context) {}
175195

@@ -253,6 +273,11 @@ public ObservableDoubleMeasurement buildObserver() {
253273
}
254274

255275
private static class NoopDoubleHistogram implements DoubleHistogram {
276+
@Override
277+
public boolean isEnabled() {
278+
return false;
279+
}
280+
256281
@Override
257282
public void record(double value, Attributes attributes, Context context) {}
258283

@@ -264,6 +289,11 @@ public void record(double value) {}
264289
}
265290

266291
private static class NoopLongHistogram implements LongHistogram {
292+
@Override
293+
public boolean isEnabled() {
294+
return false;
295+
}
296+
267297
@Override
268298
public void record(long value, Attributes attributes, Context context) {}
269299

@@ -357,6 +387,11 @@ public DoubleGauge build() {
357387
}
358388

359389
private static class NoopDoubleGauge implements DoubleGauge {
390+
@Override
391+
public boolean isEnabled() {
392+
return false;
393+
}
394+
360395
@Override
361396
public void set(double value) {}
362397

@@ -398,6 +433,11 @@ public LongGauge build() {
398433
}
399434

400435
private static class NoopLongGauge implements LongGauge {
436+
@Override
437+
public boolean isEnabled() {
438+
return false;
439+
}
440+
401441
@Override
402442
public void set(long value) {}
403443

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
*/
1717
@ThreadSafe
1818
public interface DoubleCounter {
19+
20+
/**
21+
* Returns {@code true} if the counter is enabled.
22+
*
23+
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
24+
* the response is subject to change over the application, callers should call this before each
25+
* call to {@link #add(double)}, {@link #add(double, Attributes)}, or {@link #add(double,
26+
* Attributes, Context)}.
27+
*/
28+
default boolean isEnabled() {
29+
return true;
30+
}
31+
1932
/**
2033
* Records a value.
2134
*

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
*/
1717
@ThreadSafe
1818
public interface DoubleGauge {
19+
20+
/**
21+
* Returns {@code true} if the gauge is enabled.
22+
*
23+
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
24+
* the response is subject to change over the application, callers should call this before each
25+
* call to {@link #set(double)}, {@link #set(double, Attributes)}, or {@link #set(double,
26+
* Attributes, Context)}.
27+
*/
28+
default boolean isEnabled() {
29+
return true;
30+
}
31+
1932
/**
2033
* Set the gauge value.
2134
*

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
1717
@ThreadSafe
1818
public interface DoubleHistogram {
1919

20+
/**
21+
* Returns {@code true} if the histogram is enabled.
22+
*
23+
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
24+
* the response is subject to change over the application, callers should call this before each
25+
* call to {@link #record(double)}, {@link #record(double, Attributes)}, or {@link #record(double,
26+
* Attributes, Context)}.
27+
*/
28+
default boolean isEnabled() {
29+
return true;
30+
}
31+
2032
/**
2133
* Records a value.
2234
*

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
*/
1717
@ThreadSafe
1818
public interface DoubleUpDownCounter {
19+
20+
/**
21+
* Returns {@code true} if the up down counter is enabled.
22+
*
23+
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
24+
* the response is subject to change over the application, callers should call this before each
25+
* call to {@link #add(double)}, {@link #add(double, Attributes)}, or {@link #add(double,
26+
* Attributes, Context)}.
27+
*/
28+
default boolean isEnabled() {
29+
return true;
30+
}
31+
1932
/**
2033
* Records a value.
2134
*

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
1717
@ThreadSafe
1818
public interface LongCounter {
1919

20+
/**
21+
* Returns {@code true} if the counter is enabled.
22+
*
23+
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
24+
* the response is subject to change over the application, callers should call this before each
25+
* call to {@link #add(long)}, {@link #add(long, Attributes)}, or {@link #add(long, Attributes,
26+
* Context)}.
27+
*/
28+
default boolean isEnabled() {
29+
return true;
30+
}
31+
2032
/**
2133
* Records a value.
2234
*

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
*/
1717
@ThreadSafe
1818
public interface LongGauge {
19+
20+
/**
21+
* Returns {@code true} if the gauge is enabled.
22+
*
23+
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
24+
* the response is subject to change over the application, callers should call this before each
25+
* call to {@link #set(long)}, {@link #set(long, Attributes)}, or {@link #set(long, Attributes,
26+
* Context)}.
27+
*/
28+
default boolean isEnabled() {
29+
return true;
30+
}
31+
1932
/**
2033
* Set the gauge value.
2134
*

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
1717
@ThreadSafe
1818
public interface LongHistogram {
1919

20+
/**
21+
* Returns {@code true} if the histogram is enabled.
22+
*
23+
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
24+
* the response is subject to change over the application, callers should call this before each
25+
* call to {@link #record(long)}, {@link #record(long, Attributes)}, or {@link #record(long,
26+
* Attributes, Context)}.
27+
*/
28+
default boolean isEnabled() {
29+
return true;
30+
}
31+
2032
/**
2133
* Records a value.
2234
*

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
*/
1717
@ThreadSafe
1818
public interface LongUpDownCounter {
19+
20+
/**
21+
* Returns {@code true} if the up down counter is enabled.
22+
*
23+
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
24+
* the response is subject to change over the application, callers should call this before each
25+
* call to {@link #add(long)}, {@link #add(long, Attributes)}, or {@link #add(long, Attributes,
26+
* Context)}.
27+
*/
28+
default boolean isEnabled() {
29+
return true;
30+
}
31+
1932
/**
2033
* Records a value.
2134
*

api/incubator/src/main/java/io/opentelemetry/api/incubator/metrics/ExtendedDoubleCounter.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,10 @@
55

66
package io.opentelemetry.api.incubator.metrics;
77

8-
import io.opentelemetry.api.common.Attributes;
98
import io.opentelemetry.api.metrics.DoubleCounter;
10-
import io.opentelemetry.context.Context;
119

1210
/** Extended {@link DoubleCounter} with experimental APIs. */
1311
public interface ExtendedDoubleCounter extends DoubleCounter {
1412

15-
/**
16-
* Returns {@code true} if the counter is enabled.
17-
*
18-
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
19-
* the response is subject to change over the application, callers should call this before each
20-
* call to {@link #add(double)}, {@link #add(double, Attributes)}, or {@link #add(double,
21-
* Attributes, Context)}.
22-
*/
23-
default boolean isEnabled() {
24-
return true;
25-
}
13+
// keep this class even if it is empty, since experimental methods may be added in the future.
2614
}

0 commit comments

Comments
 (0)