Skip to content

Commit 1e5b7d5

Browse files
committed
Use existing instrument interfaces as response for bind API
1 parent b091a6e commit 1e5b7d5

38 files changed

Lines changed: 787 additions & 609 deletions

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

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ class DefaultMeter implements Meter {
3131
new NoopObservableDoubleMeasurement();
3232
private static final ObservableLongMeasurement NOOP_OBSERVABLE_LONG_MEASUREMENT =
3333
new NoopObservableLongMeasurement();
34-
private static final DoubleCounterOp NOOP_DOUBLE_COUNTER_OP = value -> {};
35-
private static final LongCounterOp NOOP_LONG_COUNTER_OP = value -> {};
36-
private static final DoubleUpDownCounterOp NOOP_DOUBLE_UP_DOWN_COUNTER_OP = value -> {};
37-
private static final LongUpDownCounterOp NOOP_LONG_UP_DOWN_COUNTER_OP = value -> {};
38-
private static final DoubleHistogramOp NOOP_DOUBLE_HISTOGRAM_OP = value -> {};
39-
private static final LongHistogramOp NOOP_LONG_HISTOGRAM_OP = value -> {};
40-
private static final DoubleGaugeOp NOOP_DOUBLE_GAUGE_OP = value -> {};
41-
private static final LongGaugeOp NOOP_LONG_GAUGE_OP = value -> {};
4234

4335
static Meter getInstance() {
4436
return INSTANCE;
@@ -84,8 +76,8 @@ public boolean isEnabled() {
8476
public void add(long value, Attributes attributes, Context context) {}
8577

8678
@Override
87-
public LongCounterOp bind(Attributes attributes) {
88-
return NOOP_LONG_COUNTER_OP;
79+
public LongCounter bind(Attributes attributes) {
80+
return this;
8981
}
9082

9183
@Override
@@ -105,8 +97,8 @@ public boolean isEnabled() {
10597
public void add(double value, Attributes attributes, Context context) {}
10698

10799
@Override
108-
public DoubleCounterOp bind(Attributes attributes) {
109-
return NOOP_DOUBLE_COUNTER_OP;
100+
public DoubleCounter bind(Attributes attributes) {
101+
return this;
110102
}
111103

112104
@Override
@@ -202,8 +194,8 @@ public void add(long value, Attributes attributes) {}
202194
public void add(long value) {}
203195

204196
@Override
205-
public LongUpDownCounterOp bind(Attributes attributes) {
206-
return NOOP_LONG_UP_DOWN_COUNTER_OP;
197+
public LongUpDownCounter bind(Attributes attributes) {
198+
return this;
207199
}
208200
}
209201

@@ -223,8 +215,8 @@ public void add(double value, Attributes attributes) {}
223215
public void add(double value) {}
224216

225217
@Override
226-
public DoubleUpDownCounterOp bind(Attributes attributes) {
227-
return NOOP_DOUBLE_UP_DOWN_COUNTER_OP;
218+
public DoubleUpDownCounter bind(Attributes attributes) {
219+
return this;
228220
}
229221
}
230222

@@ -316,8 +308,8 @@ public void record(double value, Attributes attributes) {}
316308
public void record(double value) {}
317309

318310
@Override
319-
public DoubleHistogramOp bind(Attributes attributes) {
320-
return NOOP_DOUBLE_HISTOGRAM_OP;
311+
public DoubleHistogram bind(Attributes attributes) {
312+
return this;
321313
}
322314
}
323315

@@ -337,8 +329,8 @@ public void record(long value, Attributes attributes) {}
337329
public void record(long value) {}
338330

339331
@Override
340-
public LongHistogramOp bind(Attributes attributes) {
341-
return NOOP_LONG_HISTOGRAM_OP;
332+
public LongHistogram bind(Attributes attributes) {
333+
return this;
342334
}
343335
}
344336

@@ -440,8 +432,8 @@ public void set(double value, Attributes attributes) {}
440432
public void set(double value, Attributes attributes, Context context) {}
441433

442434
@Override
443-
public DoubleGaugeOp bind(Attributes attributes) {
444-
return NOOP_DOUBLE_GAUGE_OP;
435+
public DoubleGauge bind(Attributes attributes) {
436+
return this;
445437
}
446438
}
447439

@@ -491,8 +483,8 @@ public void set(long value, Attributes attributes) {}
491483
public void set(long value, Attributes attributes, Context context) {}
492484

493485
@Override
494-
public LongGaugeOp bind(Attributes attributes) {
495-
return NOOP_LONG_GAUGE_OP;
486+
public LongGauge bind(Attributes attributes) {
487+
return this;
496488
}
497489
}
498490

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @since 1.10.0
1616
*/
1717
@ThreadSafe
18-
public interface DoubleCounter extends DoubleCounterOp {
18+
public interface DoubleCounter {
1919

2020
/**
2121
* Returns {@code true} if the counter is enabled.
@@ -31,6 +31,16 @@ default boolean isEnabled() {
3131
return true;
3232
}
3333

34+
/**
35+
* Records a value.
36+
*
37+
* <p>Note: This may use {@code Context.current()} to pull the context associated with this
38+
* measurement.
39+
*
40+
* @param value The increment amount. MUST be non-negative.
41+
*/
42+
void add(double value);
43+
3444
/**
3545
* Records a value with a set of attributes.
3646
*
@@ -51,5 +61,7 @@ default boolean isEnabled() {
5161
*/
5262
void add(double value, Attributes attributes, Context context);
5363

54-
DoubleCounterOp bind(Attributes attributes);
64+
default DoubleCounter bind(Attributes attributes) {
65+
throw new UnsupportedOperationException();
66+
}
5567
}

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,7 @@ default boolean isEnabled() {
5555
*/
5656
void set(double value, Attributes attributes, Context context);
5757

58-
DoubleGaugeOp bind(Attributes attributes);
58+
default DoubleGauge bind(Attributes attributes) {
59+
throw new UnsupportedOperationException();
60+
}
5961
}

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,7 @@ default boolean isEnabled() {
6161
*/
6262
void record(double value, Attributes attributes, Context context);
6363

64-
DoubleHistogramOp bind(Attributes attributes);
64+
default DoubleHistogram bind(Attributes attributes) {
65+
throw new UnsupportedOperationException();
66+
}
6567
}

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,7 @@ default boolean isEnabled() {
6161
*/
6262
void add(double value, Attributes attributes, Context context);
6363

64-
DoubleUpDownCounterOp bind(Attributes attributes);
64+
default DoubleUpDownCounter bind(Attributes attributes) {
65+
throw new UnsupportedOperationException();
66+
}
6567
}

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @since 1.10.0
1616
*/
1717
@ThreadSafe
18-
public interface LongCounter extends LongCounterOp {
18+
public interface LongCounter {
1919

2020
/**
2121
* Returns {@code true} if the counter is enabled.
@@ -31,6 +31,16 @@ default boolean isEnabled() {
3131
return true;
3232
}
3333

34+
/**
35+
* Records a value.
36+
*
37+
* <p>Note: This may use {@code Context.current()} to pull the context associated with this
38+
* measurement.
39+
*
40+
* @param value The increment amount. MUST be non-negative.
41+
*/
42+
void add(long value);
43+
3444
/**
3545
* Records a value with a set of attributes.
3646
*
@@ -51,5 +61,7 @@ default boolean isEnabled() {
5161
*/
5262
void add(long value, Attributes attributes, Context context);
5363

54-
LongCounterOp bind(Attributes attributes);
64+
default LongCounter bind(Attributes attributes) {
65+
throw new UnsupportedOperationException();
66+
}
5567
}

0 commit comments

Comments
 (0)