From 46b8bc1189edc30baf84c32bf44f9233aea07b19 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Sat, 25 Oct 2025 01:07:04 -0700 Subject: [PATCH 1/7] Add support to remove instruments --- .../api/metrics/DefaultMeter.java | 48 +++++++++++++++++++ .../api/metrics/DoubleCounter.java | 15 ++++++ .../api/metrics/DoubleGauge.java | 15 ++++++ .../api/metrics/DoubleHistogram.java | 15 ++++++ .../api/metrics/DoubleUpDownCounter.java | 15 ++++++ .../api/metrics/LongCounter.java | 15 ++++++ .../opentelemetry/api/metrics/LongGauge.java | 15 ++++++ .../api/metrics/LongHistogram.java | 15 ++++++ .../api/metrics/LongUpDownCounter.java | 15 ++++++ .../metrics/ExtendedDefaultMeter.java | 48 +++++++++++++++++++ .../current_vs_latest/opentelemetry-api.txt | 33 ++++++++++++- .../sdk/metrics/SdkDoubleCounter.java | 10 ++++ .../sdk/metrics/SdkDoubleGauge.java | 10 ++++ .../sdk/metrics/SdkDoubleHistogram.java | 10 ++++ .../sdk/metrics/SdkDoubleUpDownCounter.java | 10 ++++ .../sdk/metrics/SdkLongCounter.java | 10 ++++ .../sdk/metrics/SdkLongGauge.java | 10 ++++ .../sdk/metrics/SdkLongHistogram.java | 10 ++++ .../sdk/metrics/SdkLongUpDownCounter.java | 10 ++++ .../opentelemetry/sdk/metrics/SdkMeter.java | 7 +++ .../DefaultSynchronousMetricStorage.java | 13 +++++ .../internal/state/EmptyMetricStorage.java | 3 ++ .../state/WriteableMetricStorage.java | 3 ++ .../sdk/metrics/SdkDoubleCounterTest.java | 9 ++++ .../sdk/metrics/SdkDoubleGaugeTest.java | 12 +++++ .../sdk/metrics/SdkDoubleHistogramTest.java | 11 +++++ .../metrics/SdkDoubleUpDownCounterTest.java | 12 +++++ .../sdk/metrics/SdkLongCounterTest.java | 9 ++++ .../sdk/metrics/SdkLongGaugeTest.java | 10 ++++ .../sdk/metrics/SdkLongHistogramTest.java | 11 +++++ .../sdk/metrics/SdkLongUpDownCounterTest.java | 11 +++++ .../state/MetricStorageRegistryTest.java | 3 ++ 32 files changed, 442 insertions(+), 1 deletion(-) diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java index fff36ae9cbb..5f75a572a81 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java @@ -75,6 +75,12 @@ public void add(long value, Attributes attributes) {} @Override public void add(long value) {} + + @Override + public void remove(Attributes attributes) {} + + @Override + public void remove(Attributes attributes, Context context) {} } private static class NoopDoubleCounter implements DoubleCounter { @@ -86,6 +92,12 @@ public void add(double value, Attributes attributes) {} @Override public void add(double value) {} + + @Override + public void remove(Attributes attributes) {} + + @Override + public void remove(Attributes attributes, Context context) {} } private static class NoopLongCounterBuilder implements LongCounterBuilder { @@ -167,6 +179,12 @@ public void add(long value, Attributes attributes) {} @Override public void add(long value) {} + + @Override + public void remove(Attributes attributes) {} + + @Override + public void remove(Attributes attributes, Context context) {} } private static class NoopDoubleUpDownCounter implements DoubleUpDownCounter { @@ -178,6 +196,12 @@ public void add(double value, Attributes attributes) {} @Override public void add(double value) {} + + @Override + public void remove(Attributes attributes) {} + + @Override + public void remove(Attributes attributes, Context context) {} } private static class NoopLongUpDownCounterBuilder implements LongUpDownCounterBuilder { @@ -261,6 +285,12 @@ public void record(double value, Attributes attributes) {} @Override public void record(double value) {} + + @Override + public void remove(Attributes attributes) {} + + @Override + public void remove(Attributes attributes, Context context) {} } private static class NoopLongHistogram implements LongHistogram { @@ -272,6 +302,12 @@ public void record(long value, Attributes attributes) {} @Override public void record(long value) {} + + @Override + public void remove(Attributes attributes) {} + + @Override + public void remove(Attributes attributes, Context context) {} } private static class NoopDoubleHistogramBuilder implements DoubleHistogramBuilder { @@ -365,6 +401,12 @@ public void set(double value, Attributes attributes) {} @Override public void set(double value, Attributes attributes, Context context) {} + + @Override + public void remove(Attributes attributes) {} + + @Override + public void remove(Attributes attributes, Context context) {} } private static class NoopLongGaugeBuilder implements LongGaugeBuilder { @@ -406,6 +448,12 @@ public void set(long value, Attributes attributes) {} @Override public void set(long value, Attributes attributes, Context context) {} + + @Override + public void remove(Attributes attributes) {} + + @Override + public void remove(Attributes attributes, Context context) {} } private static class NoopObservableDoubleMeasurement implements ObservableDoubleMeasurement { diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleCounter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleCounter.java index 1934b937379..bf5fa39246c 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleCounter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleCounter.java @@ -45,4 +45,19 @@ public interface DoubleCounter { * @param context The explicit context to associate with this measurement. */ void add(double value, Attributes attributes, Context context); + + /** + * Remove the instrument. + * + * @param attributes A set of attributes to identify the instrument. + */ + void remove(Attributes attributes); + + /** + * Remove the instrument. + * + * @param attributes A set of attributes to identify the instrument. + * @param context The explicit context to associate with this measurement. + */ + void remove(Attributes attributes, Context context); } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleGauge.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleGauge.java index a755ff25b16..15dd7d8504d 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleGauge.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleGauge.java @@ -39,4 +39,19 @@ public interface DoubleGauge { * @param context The explicit context to associate with this measurement. */ void set(double value, Attributes attributes, Context context); + + /** + * Remove the instrument. + * + * @param attributes A set of attributes to identify the instrument. + */ + void remove(Attributes attributes); + + /** + * Remove the instrument. + * + * @param attributes A set of attributes to identify the instrument. + * @param context The explicit context to associate with this measurement. + */ + void remove(Attributes attributes, Context context); } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleHistogram.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleHistogram.java index 07b45531294..b371fa23e9d 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleHistogram.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleHistogram.java @@ -46,4 +46,19 @@ public interface DoubleHistogram { * @param context The explicit context to associate with this measurement. */ void record(double value, Attributes attributes, Context context); + + /** + * Remove the instrument. + * + * @param attributes A set of attributes to identify the instrument. + */ + void remove(Attributes attributes); + + /** + * Remove the instrument. + * + * @param attributes A set of attributes to identify the instrument. + * @param context The explicit context to associate with this measurement. + */ + void remove(Attributes attributes, Context context); } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleUpDownCounter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleUpDownCounter.java index 7c6187b8a83..a7d5d2482c3 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleUpDownCounter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleUpDownCounter.java @@ -45,4 +45,19 @@ public interface DoubleUpDownCounter { * @param context The explicit context to associate with this measurement. */ void add(double value, Attributes attributes, Context context); + + /** + * Remove the instrument. + * + * @param attributes A set of attributes to identify the instrument. + */ + void remove(Attributes attributes); + + /** + * Remove the instrument. + * + * @param attributes A set of attributes to identify the instrument. + * @param context The explicit context to associate with this measurement. + */ + void remove(Attributes attributes, Context context); } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/LongCounter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/LongCounter.java index fee520f0c11..8ca92d2c784 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/LongCounter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/LongCounter.java @@ -46,4 +46,19 @@ public interface LongCounter { * @param context The explicit context to associate with this measurement. */ void add(long value, Attributes attributes, Context context); + + /** + * Remove the instrument. + * + * @param attributes A set of attributes to identify the instrument. + */ + void remove(Attributes attributes); + + /** + * Remove the instrument. + * + * @param attributes A set of attributes to identify the instrument. + * @param context The explicit context to associate with this measurement. + */ + void remove(Attributes attributes, Context context); } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/LongGauge.java b/api/all/src/main/java/io/opentelemetry/api/metrics/LongGauge.java index 018f60e323b..1984c2f3745 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/LongGauge.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/LongGauge.java @@ -39,4 +39,19 @@ public interface LongGauge { * @param context The explicit context to associate with this measurement. */ void set(long value, Attributes attributes, Context context); + + /** + * Remove the instrument. + * + * @param attributes A set of attributes to identify the instrument. + */ + void remove(Attributes attributes); + + /** + * Remove the instrument. + * + * @param attributes A set of attributes to identify the instrument. + * @param context The explicit context to associate with this measurement. + */ + void remove(Attributes attributes, Context context); } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/LongHistogram.java b/api/all/src/main/java/io/opentelemetry/api/metrics/LongHistogram.java index ba8bed7e376..a542e05c0a9 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/LongHistogram.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/LongHistogram.java @@ -46,4 +46,19 @@ public interface LongHistogram { * @param context The explicit context to associate with this measurement. */ void record(long value, Attributes attributes, Context context); + + /** + * Remove the instrument. + * + * @param attributes A set of attributes to identify the instrument. + */ + void remove(Attributes attributes); + + /** + * Remove the instrument. + * + * @param attributes A set of attributes to identify the instrument. + * @param context The explicit context to associate with this measurement. + */ + void remove(Attributes attributes, Context context); } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/LongUpDownCounter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/LongUpDownCounter.java index f9106c12deb..af819a7a893 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/LongUpDownCounter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/LongUpDownCounter.java @@ -45,4 +45,19 @@ public interface LongUpDownCounter { * @param context The explicit context to associate with this measurement. */ void add(long value, Attributes attributes, Context context); + + /** + * Remove the instrument. + * + * @param attributes A set of attributes to identify the instrument. + */ + void remove(Attributes attributes); + + /** + * Remove the instrument. + * + * @param attributes A set of attributes to identify the instrument. + * @param context The explicit context to associate with this measurement. + */ + void remove(Attributes attributes, Context context); } diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/metrics/ExtendedDefaultMeter.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/metrics/ExtendedDefaultMeter.java index 8283c7bb0b6..6ad26adc4bf 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/metrics/ExtendedDefaultMeter.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/metrics/ExtendedDefaultMeter.java @@ -107,6 +107,12 @@ public void add(long value, Attributes attributes) {} @Override public void add(long value) {} + + @Override + public void remove(Attributes attributes) {} + + @Override + public void remove(Attributes attributes, Context context) {} } private static class NoopDoubleCounter implements ExtendedDoubleCounter { @@ -123,6 +129,12 @@ public void add(double value, Attributes attributes) {} @Override public void add(double value) {} + + @Override + public void remove(Attributes attributes) {} + + @Override + public void remove(Attributes attributes, Context context) {} } private static class NoopLongCounterBuilder implements ExtendedLongCounterBuilder { @@ -209,6 +221,12 @@ public void add(long value, Attributes attributes) {} @Override public void add(long value) {} + + @Override + public void remove(Attributes attributes) {} + + @Override + public void remove(Attributes attributes, Context context) {} } private static class NoopDoubleUpDownCounter implements ExtendedDoubleUpDownCounter { @@ -225,6 +243,12 @@ public void add(double value, Attributes attributes) {} @Override public void add(double value) {} + + @Override + public void remove(Attributes attributes) {} + + @Override + public void remove(Attributes attributes, Context context) {} } private static class NoopLongUpDownCounterBuilder implements ExtendedLongUpDownCounterBuilder { @@ -314,6 +338,12 @@ public void record(double value, Attributes attributes) {} @Override public void record(double value) {} + + @Override + public void remove(Attributes attributes) {} + + @Override + public void remove(Attributes attributes, Context context) {} } private static class NoopLongHistogram implements ExtendedLongHistogram { @@ -330,6 +360,12 @@ public void record(long value, Attributes attributes) {} @Override public void record(long value) {} + + @Override + public void remove(Attributes attributes) {} + + @Override + public void remove(Attributes attributes, Context context) {} } private static class NoopDoubleHistogramBuilder implements ExtendedDoubleHistogramBuilder { @@ -428,6 +464,12 @@ public void set(double value, Attributes attributes) {} @Override public void set(double value, Attributes attributes, Context context) {} + + @Override + public void remove(Attributes attributes) {} + + @Override + public void remove(Attributes attributes, Context context) {} } private static class NoopLongGaugeBuilder implements ExtendedLongGaugeBuilder { @@ -474,6 +516,12 @@ public void set(long value, Attributes attributes) {} @Override public void set(long value, Attributes attributes, Context context) {} + + @Override + public void remove(Attributes attributes) {} + + @Override + public void remove(Attributes attributes, Context context) {} } private static class NoopObservableDoubleMeasurement implements ObservableDoubleMeasurement { diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-api.txt b/docs/apidiffs/current_vs_latest/opentelemetry-api.txt index a190a108853..b8d1bdf1445 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-api.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-api.txt @@ -1,2 +1,33 @@ Comparing source compatibility of opentelemetry-api-1.61.0-SNAPSHOT.jar against opentelemetry-api-1.60.1.jar -No changes. \ No newline at end of file +**** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.DoubleCounter (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes) + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) +**** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.DoubleGauge (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes) + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) +**** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.DoubleHistogram (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes) + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) +**** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.DoubleUpDownCounter (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes) + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) +**** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.LongCounter (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes) + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) +**** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.LongGauge (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes) + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) +**** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.LongHistogram (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes) + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) +**** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.LongUpDownCounter (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes) + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleCounter.java index bdcb30bbc61..aa1523f220c 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleCounter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleCounter.java @@ -56,6 +56,16 @@ public void add(double increment) { add(increment, Attributes.empty()); } + @Override + public void remove(Attributes attributes) { + remove(attributes, Context.current()); + } + + @Override + public void remove(Attributes attributes, Context context) { + storage.remove(attributes, context); + } + static class SdkDoubleCounterBuilder implements DoubleCounterBuilder { final InstrumentBuilder builder; diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleGauge.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleGauge.java index 6bbdaf5355e..9bb40073ffa 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleGauge.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleGauge.java @@ -43,6 +43,16 @@ public void set(double value) { set(value, Attributes.empty()); } + @Override + public void remove(Attributes attributes) { + remove(attributes, Context.current()); + } + + @Override + public void remove(Attributes attributes, Context context) { + storage.remove(attributes, context); + } + static class SdkDoubleGaugeBuilder implements DoubleGaugeBuilder { final InstrumentBuilder builder; diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogram.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogram.java index 15f0f5ea44d..b93edb8dc7f 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogram.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogram.java @@ -56,6 +56,16 @@ public void record(double value) { record(value, Attributes.empty()); } + @Override + public void remove(Attributes attributes) { + remove(attributes, Context.current()); + } + + @Override + public void remove(Attributes attributes, Context context) { + storage.remove(attributes, context); + } + static class SdkDoubleHistogramBuilder implements DoubleHistogramBuilder { final InstrumentBuilder builder; diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounter.java index 4231f58fdc0..5d0948ea6d4 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounter.java @@ -43,6 +43,16 @@ public void add(double increment) { add(increment, Attributes.empty()); } + @Override + public void remove(Attributes attributes) { + remove(attributes, Context.current()); + } + + @Override + public void remove(Attributes attributes, Context context) { + storage.remove(attributes, context); + } + static class SdkDoubleUpDownCounterBuilder implements DoubleUpDownCounterBuilder { final InstrumentBuilder builder; diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongCounter.java index b26004835d2..53df6302e60 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongCounter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongCounter.java @@ -57,6 +57,16 @@ public void add(long increment) { add(increment, Attributes.empty()); } + @Override + public void remove(Attributes attributes) { + remove(attributes, Context.current()); + } + + @Override + public void remove(Attributes attributes, Context context) { + storage.remove(attributes, context); + } + static class SdkLongCounterBuilder implements LongCounterBuilder { final InstrumentBuilder builder; diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongGauge.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongGauge.java index 4140dfb42bf..187f4ca8add 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongGauge.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongGauge.java @@ -42,6 +42,16 @@ public void set(long value) { set(value, Attributes.empty()); } + @Override + public void remove(Attributes attributes) { + remove(attributes, Context.current()); + } + + @Override + public void remove(Attributes attributes, Context context) { + storage.remove(attributes, context); + } + static class SdkLongGaugeBuilder implements LongGaugeBuilder { final InstrumentBuilder builder; diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongHistogram.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongHistogram.java index 4f935d0d091..8fde8702085 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongHistogram.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongHistogram.java @@ -57,6 +57,16 @@ public void record(long value) { record(value, Attributes.empty()); } + @Override + public void remove(Attributes attributes) { + remove(attributes, Context.current()); + } + + @Override + public void remove(Attributes attributes, Context context) { + storage.remove(attributes, context); + } + static class SdkLongHistogramBuilder implements LongHistogramBuilder { final InstrumentBuilder builder; diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounter.java index dece771f4b6..130b3800815 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounter.java @@ -43,6 +43,16 @@ public void add(long increment) { add(increment, Attributes.empty()); } + @Override + public void remove(Attributes attributes) { + remove(attributes, Context.current()); + } + + @Override + public void remove(Attributes attributes, Context context) { + storage.remove(attributes, context); + } + static class SdkLongUpDownCounterBuilder implements LongUpDownCounterBuilder { final InstrumentBuilder builder; diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkMeter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkMeter.java index 01dead0ce85..bb2ffe426e8 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkMeter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkMeter.java @@ -369,6 +369,13 @@ public void recordDouble(double value, Attributes attributes, Context context) { } } + @Override + public void remove(Attributes attributes, Context context) { + for (WriteableMetricStorage storage : storages) { + storage.remove(attributes, context); + } + } + @Override public boolean isEnabled() { for (WriteableMetricStorage storage : storages) { diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/DefaultSynchronousMetricStorage.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/DefaultSynchronousMetricStorage.java index a746c00dec0..bb1eb7ead9c 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/DefaultSynchronousMetricStorage.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/DefaultSynchronousMetricStorage.java @@ -124,6 +124,19 @@ public void recordDouble(double value, Attributes attributes, Context context) { abstract void doRecordDouble(double value, Attributes attributes, Context context); + @Override + public void remove(Attributes attributes, Context context) { + if (!enabled) { + return; + } + AggregatorHolder aggregatorHolder = getHolderForRecord(); + try { + aggregatorHolder.aggregatorHandles.remove(attributes); + } finally { + releaseHolderForRecord(aggregatorHolder); + } + } + @Override public void setEnabled(boolean enabled) { this.enabled = enabled; diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/EmptyMetricStorage.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/EmptyMetricStorage.java index 9a0ed207877..5af10fee1a5 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/EmptyMetricStorage.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/EmptyMetricStorage.java @@ -40,6 +40,9 @@ public void recordLong(long value, Attributes attributes, Context context) {} @Override public void recordDouble(double value, Attributes attributes, Context context) {} + @Override + public void remove(Attributes attributes, Context context) {} + @Override public boolean isEnabled() { return false; diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/WriteableMetricStorage.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/WriteableMetricStorage.java index 7191a63f1e0..61b562cbf51 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/WriteableMetricStorage.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/WriteableMetricStorage.java @@ -23,6 +23,9 @@ public interface WriteableMetricStorage { /** Records a measurement. */ void recordDouble(double value, Attributes attributes, Context context); + /** Remove a measurement. */ + void remove(Attributes attributes, Context context); + /** * Returns {@code true} if the storage is actively recording measurements, and {@code false} * otherwise (i.e. noop / empty metric storage is installed). diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleCounterTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleCounterTest.java index 34882efc751..f45d996df41 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleCounterTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleCounterTest.java @@ -57,6 +57,15 @@ void collectMetrics_NoRecords() { assertThat(sdkMeterReader.collectAllMetrics()).isEmpty(); } + @Test + void collectMetrics_Remove() { + DoubleCounter counter = sdkMeter.counterBuilder("testCounter").ofDoubles().build(); + Attributes attrs = Attributes.of(stringKey("key"), "value"); + counter.add(1, attrs); + counter.remove(attrs); + assertThat(sdkMeterReader.collectAllMetrics()).isEmpty(); + } + @Test void collectMetrics_WithEmptyAttributes() { DoubleCounter doubleCounter = diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleGaugeTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleGaugeTest.java index 740775e766f..52ffaa5b5d1 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleGaugeTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleGaugeTest.java @@ -27,6 +27,8 @@ import io.opentelemetry.sdk.trace.SdkTracerProvider; import java.time.Duration; import java.util.Collections; +import java.util.stream.IntStream; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; /** Unit tests for {@link SdkDoubleGauge}. */ @@ -96,6 +98,16 @@ void collectMetrics_NoRecords() { assertThat(cumulativeReader.collectAllMetrics()).isEmpty(); } + @Test + void collectMetrics_Remove() { + DoubleGauge gauge = sdkMeter.gaugeBuilder("testGauge").build(); + assertThat(cumulativeReader.collectAllMetrics()).isEmpty(); + Attributes attrs = Attributes.of(stringKey("key"), "value"); + gauge.set(1, attrs); + gauge.remove(attrs); + Assertions.assertThat(cumulativeReader.collectAllMetrics()).isEmpty(); + } + @Test void collectMetrics_WithEmptyAttributes() { DoubleGauge doubleGauge = diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogramTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogramTest.java index c06948acf88..f7bd1e8e040 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogramTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogramTest.java @@ -27,6 +27,8 @@ import java.time.Duration; import java.util.Arrays; import java.util.Collections; +import java.util.stream.IntStream; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -63,6 +65,15 @@ void collectMetrics_NoRecords() { assertThat(sdkMeterReader.collectAllMetrics()).isEmpty(); } + @Test + void collectMetrics_Remove() { + DoubleHistogram histogram = sdkMeter.histogramBuilder("testHistogram").build(); + Attributes attrs = Attributes.of(stringKey("key"), "value"); + histogram.record(1, attrs); + histogram.remove(attrs); + Assertions.assertThat(sdkMeterReader.collectAllMetrics()).isEmpty(); + } + @Test void collectMetrics_WithEmptyAttributes() { DoubleHistogram doubleHistogram = diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounterTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounterTest.java index a15dcf422cc..5a4307dd8d9 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounterTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounterTest.java @@ -18,6 +18,8 @@ import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.sdk.testing.time.TestClock; import java.time.Duration; +import java.util.stream.IntStream; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; /** Unit tests for {@link SdkDoubleUpDownCounter}. */ @@ -56,6 +58,16 @@ void collectMetrics_NoRecords() { assertThat(sdkMeterReader.collectAllMetrics()).isEmpty(); } + @Test + void collectMetrics_Remove() { + DoubleUpDownCounter counter = + sdkMeter.upDownCounterBuilder("testUpDownCounter").ofDoubles().build(); + Attributes attrs = Attributes.of(stringKey("key"), "value"); + counter.add(1, attrs); + counter.remove(attrs); + Assertions.assertThat(sdkMeterReader.collectAllMetrics()).isEmpty(); + } + @Test void collectMetrics_WithEmptyAttributes() { DoubleUpDownCounter doubleUpDownCounter = diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongCounterTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongCounterTest.java index 160a07b9e48..a4a4d590c43 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongCounterTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongCounterTest.java @@ -55,6 +55,15 @@ void collectMetrics_NoRecords() { assertThat(sdkMeterReader.collectAllMetrics()).isEmpty(); } + @Test + void collectMetrics_Remove() { + LongCounter counter = sdkMeter.counterBuilder("Counter").build(); + Attributes attrs = Attributes.of(stringKey("key"), "value"); + counter.add(1, attrs); + counter.remove(attrs); + assertThat(sdkMeterReader.collectAllMetrics()).isEmpty(); + } + @Test void collectMetrics_WithEmptyAttributes() { LongCounter longCounter = diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongGaugeTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongGaugeTest.java index 3879f2e8a76..fdeb4c7d564 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongGaugeTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongGaugeTest.java @@ -80,6 +80,16 @@ void collectMetrics_NoRecords() { assertThat(cumulativeReader.collectAllMetrics()).isEmpty(); } + @Test + void collectMetrics_Remove() { + LongGauge gauge = sdkMeter.gaugeBuilder("testGauge").ofLongs().build(); + assertThat(cumulativeReader.collectAllMetrics()).isEmpty(); + Attributes attrs = Attributes.of(stringKey("key"), "value"); + gauge.set(1, attrs); + gauge.remove(attrs); + Assertions.assertThat(cumulativeReader.collectAllMetrics()).isEmpty(); + } + @Test void collectMetrics_WithEmptyAttributes() { LongGauge longGauge = diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongHistogramTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongHistogramTest.java index 1f0321f55bf..7b42c2149d6 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongHistogramTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongHistogramTest.java @@ -26,6 +26,8 @@ import java.time.Duration; import java.util.Arrays; import java.util.Collections; +import java.util.stream.IntStream; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -62,6 +64,15 @@ void collectMetrics_NoRecords() { assertThat(reader.collectAllMetrics()).isEmpty(); } + @Test + void collectMetrics_Remove() { + LongHistogram histogram = sdkMeter.histogramBuilder("testHistogram").ofLongs().build(); + Attributes attrs = Attributes.of(stringKey("key"), "value"); + histogram.record(1, attrs); + histogram.remove(attrs); + Assertions.assertThat(reader.collectAllMetrics()).isEmpty(); + } + @Test void collectMetrics_WithEmptyAttributes() { LongHistogram longHistogram = diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounterTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounterTest.java index 39eb6500207..3e9770a2758 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounterTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounterTest.java @@ -18,6 +18,8 @@ import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.sdk.testing.time.TestClock; import java.time.Duration; +import java.util.stream.IntStream; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; /** Unit tests for {@link SdkLongUpDownCounter}. */ @@ -50,6 +52,15 @@ void collectMetrics_NoRecords() { assertThat(sdkMeterReader.collectAllMetrics()).isEmpty(); } + @Test + void collectMetrics_Remove() { + LongUpDownCounter counter = sdkMeter.upDownCounterBuilder("testUpDownCounter").build(); + Attributes attrs = Attributes.of(stringKey("key"), "value"); + counter.add(1, attrs); + counter.remove(attrs); + Assertions.assertThat(sdkMeterReader.collectAllMetrics()).isEmpty(); + } + @Test void collectMetrics_WithEmptyAttributes() { LongUpDownCounter longUpDownCounter = diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/state/MetricStorageRegistryTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/state/MetricStorageRegistryTest.java index 9f91d13fe24..563f6fa5cbe 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/state/MetricStorageRegistryTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/state/MetricStorageRegistryTest.java @@ -115,6 +115,9 @@ public void recordLong(long value, Attributes attributes, Context context) {} @Override public void recordDouble(double value, Attributes attributes, Context context) {} + @Override + public void remove(Attributes attributes, Context context) {} + @Override public boolean isEnabled() { return true; From abed63f5986fe60eb0174f8c0c3167c61c943dd2 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Mon, 27 Oct 2025 16:26:02 -0700 Subject: [PATCH 2/7] implement default behavior to avoid breaking change --- .../api/metrics/DefaultMeter.java | 24 ---------- .../api/metrics/DoubleCounter.java | 11 +++-- .../api/metrics/DoubleGauge.java | 10 +++- .../api/metrics/DoubleHistogram.java | 11 +++-- .../api/metrics/DoubleUpDownCounter.java | 11 +++-- .../api/metrics/LongCounter.java | 11 +++-- .../opentelemetry/api/metrics/LongGauge.java | 11 +++-- .../api/metrics/LongHistogram.java | 11 +++-- .../api/metrics/LongUpDownCounter.java | 10 +++- .../metrics/ExtendedDefaultMeter.java | 24 ---------- .../current_vs_latest/opentelemetry-api.txt | 47 ++++++++++--------- .../sdk/metrics/SdkDoubleCounter.java | 5 -- .../sdk/metrics/SdkDoubleGauge.java | 5 -- .../sdk/metrics/SdkDoubleHistogram.java | 5 -- .../sdk/metrics/SdkDoubleUpDownCounter.java | 5 -- .../sdk/metrics/SdkLongCounter.java | 5 -- .../sdk/metrics/SdkLongGauge.java | 5 -- .../sdk/metrics/SdkLongHistogram.java | 5 -- .../sdk/metrics/SdkLongUpDownCounter.java | 5 -- 19 files changed, 88 insertions(+), 133 deletions(-) diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java index 5f75a572a81..0a2a36f9a50 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java @@ -76,9 +76,6 @@ public void add(long value, Attributes attributes) {} @Override public void add(long value) {} - @Override - public void remove(Attributes attributes) {} - @Override public void remove(Attributes attributes, Context context) {} } @@ -93,9 +90,6 @@ public void add(double value, Attributes attributes) {} @Override public void add(double value) {} - @Override - public void remove(Attributes attributes) {} - @Override public void remove(Attributes attributes, Context context) {} } @@ -180,9 +174,6 @@ public void add(long value, Attributes attributes) {} @Override public void add(long value) {} - @Override - public void remove(Attributes attributes) {} - @Override public void remove(Attributes attributes, Context context) {} } @@ -197,9 +188,6 @@ public void add(double value, Attributes attributes) {} @Override public void add(double value) {} - @Override - public void remove(Attributes attributes) {} - @Override public void remove(Attributes attributes, Context context) {} } @@ -286,9 +274,6 @@ public void record(double value, Attributes attributes) {} @Override public void record(double value) {} - @Override - public void remove(Attributes attributes) {} - @Override public void remove(Attributes attributes, Context context) {} } @@ -303,9 +288,6 @@ public void record(long value, Attributes attributes) {} @Override public void record(long value) {} - @Override - public void remove(Attributes attributes) {} - @Override public void remove(Attributes attributes, Context context) {} } @@ -402,9 +384,6 @@ public void set(double value, Attributes attributes) {} @Override public void set(double value, Attributes attributes, Context context) {} - @Override - public void remove(Attributes attributes) {} - @Override public void remove(Attributes attributes, Context context) {} } @@ -449,9 +428,6 @@ public void set(long value, Attributes attributes) {} @Override public void set(long value, Attributes attributes, Context context) {} - @Override - public void remove(Attributes attributes) {} - @Override public void remove(Attributes attributes, Context context) {} } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleCounter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleCounter.java index bf5fa39246c..7279b0a369e 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleCounter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleCounter.java @@ -50,14 +50,19 @@ public interface DoubleCounter { * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. + * + * @since 1.56.0 */ - void remove(Attributes attributes); - + default void remove(Attributes attributes) { + remove(attributes, Context.current()); + } /** * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. + * + * @since 1.56.0 */ - void remove(Attributes attributes, Context context); + default void remove(Attributes attributes, Context context) {} } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleGauge.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleGauge.java index 15dd7d8504d..3879ef524f2 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleGauge.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleGauge.java @@ -44,14 +44,20 @@ public interface DoubleGauge { * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. + * + * @since 1.56.0 */ - void remove(Attributes attributes); + default void remove(Attributes attributes) { + remove(attributes, Context.current()); + } /** * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. + * + * @since 1.56.0 */ - void remove(Attributes attributes, Context context); + default void remove(Attributes attributes, Context context) {} } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleHistogram.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleHistogram.java index b371fa23e9d..d34c43e74ab 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleHistogram.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleHistogram.java @@ -51,14 +51,19 @@ public interface DoubleHistogram { * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. + * + * @since 1.56.0 */ - void remove(Attributes attributes); - + default void remove(Attributes attributes) { + remove(attributes, Context.current()); + } /** * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. + * + * @since 1.56.0 */ - void remove(Attributes attributes, Context context); + default void remove(Attributes attributes, Context context) {} } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleUpDownCounter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleUpDownCounter.java index a7d5d2482c3..75e64d9f224 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleUpDownCounter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleUpDownCounter.java @@ -50,14 +50,19 @@ public interface DoubleUpDownCounter { * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. + * + * @since 1.56.0 */ - void remove(Attributes attributes); - + default void remove(Attributes attributes) { + remove(attributes, Context.current()); + } /** * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. + * + * @since 1.56.0 */ - void remove(Attributes attributes, Context context); + default void remove(Attributes attributes, Context context) {} } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/LongCounter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/LongCounter.java index 8ca92d2c784..9b25854a7be 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/LongCounter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/LongCounter.java @@ -51,14 +51,19 @@ public interface LongCounter { * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. + * + * @since 1.56.0 */ - void remove(Attributes attributes); - + default void remove(Attributes attributes) { + remove(attributes, Context.current()); + } /** * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. + * + * @since 1.56.0 */ - void remove(Attributes attributes, Context context); + default void remove(Attributes attributes, Context context) {} } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/LongGauge.java b/api/all/src/main/java/io/opentelemetry/api/metrics/LongGauge.java index 1984c2f3745..4e99ae004fe 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/LongGauge.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/LongGauge.java @@ -44,14 +44,19 @@ public interface LongGauge { * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. + * + * @since 1.56.0 */ - void remove(Attributes attributes); - + default void remove(Attributes attributes) { + remove(attributes, Context.current()); + } /** * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. + * + * @since 1.56.0 */ - void remove(Attributes attributes, Context context); + default void remove(Attributes attributes, Context context) {} } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/LongHistogram.java b/api/all/src/main/java/io/opentelemetry/api/metrics/LongHistogram.java index a542e05c0a9..e356cd14f42 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/LongHistogram.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/LongHistogram.java @@ -51,14 +51,19 @@ public interface LongHistogram { * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. + * + * @since 1.56.0 */ - void remove(Attributes attributes); - + default void remove(Attributes attributes) { + remove(attributes, Context.current()); + } /** * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. + * + * @since 1.56.0 */ - void remove(Attributes attributes, Context context); + default void remove(Attributes attributes, Context context) {} } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/LongUpDownCounter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/LongUpDownCounter.java index af819a7a893..1aebc461bc6 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/LongUpDownCounter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/LongUpDownCounter.java @@ -50,14 +50,20 @@ public interface LongUpDownCounter { * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. + * + * @since 1.56.0 */ - void remove(Attributes attributes); + default void remove(Attributes attributes) { + remove(attributes, Context.current()); + } /** * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. + * + * @since 1.56.0 */ - void remove(Attributes attributes, Context context); + default void remove(Attributes attributes, Context context) {} } diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/metrics/ExtendedDefaultMeter.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/metrics/ExtendedDefaultMeter.java index 6ad26adc4bf..0b1937b8f64 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/metrics/ExtendedDefaultMeter.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/metrics/ExtendedDefaultMeter.java @@ -108,9 +108,6 @@ public void add(long value, Attributes attributes) {} @Override public void add(long value) {} - @Override - public void remove(Attributes attributes) {} - @Override public void remove(Attributes attributes, Context context) {} } @@ -130,9 +127,6 @@ public void add(double value, Attributes attributes) {} @Override public void add(double value) {} - @Override - public void remove(Attributes attributes) {} - @Override public void remove(Attributes attributes, Context context) {} } @@ -222,9 +216,6 @@ public void add(long value, Attributes attributes) {} @Override public void add(long value) {} - @Override - public void remove(Attributes attributes) {} - @Override public void remove(Attributes attributes, Context context) {} } @@ -244,9 +235,6 @@ public void add(double value, Attributes attributes) {} @Override public void add(double value) {} - @Override - public void remove(Attributes attributes) {} - @Override public void remove(Attributes attributes, Context context) {} } @@ -339,9 +327,6 @@ public void record(double value, Attributes attributes) {} @Override public void record(double value) {} - @Override - public void remove(Attributes attributes) {} - @Override public void remove(Attributes attributes, Context context) {} } @@ -361,9 +346,6 @@ public void record(long value, Attributes attributes) {} @Override public void record(long value) {} - @Override - public void remove(Attributes attributes) {} - @Override public void remove(Attributes attributes, Context context) {} } @@ -465,9 +447,6 @@ public void set(double value, Attributes attributes) {} @Override public void set(double value, Attributes attributes, Context context) {} - @Override - public void remove(Attributes attributes) {} - @Override public void remove(Attributes attributes, Context context) {} } @@ -517,9 +496,6 @@ public void set(long value, Attributes attributes) {} @Override public void set(long value, Attributes attributes, Context context) {} - @Override - public void remove(Attributes attributes) {} - @Override public void remove(Attributes attributes, Context context) {} } diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-api.txt b/docs/apidiffs/current_vs_latest/opentelemetry-api.txt index b8d1bdf1445..03451be5abe 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-api.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-api.txt @@ -1,33 +1,34 @@ Comparing source compatibility of opentelemetry-api-1.61.0-SNAPSHOT.jar against opentelemetry-api-1.60.1.jar **** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.DoubleCounter (not serializable) +*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.DoubleCounter (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes) - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) -**** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.DoubleGauge (not serializable) + +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes) + +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) +*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.DoubleGauge (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes) - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) -**** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.DoubleHistogram (not serializable) + +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes) + +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) +*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.DoubleHistogram (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes) - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) -**** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.DoubleUpDownCounter (not serializable) + +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes) + +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) +*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.DoubleUpDownCounter (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes) - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) -**** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.LongCounter (not serializable) + +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes) + +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) +*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.LongCounter (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes) - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) -**** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.LongGauge (not serializable) + +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes) + +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) +*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.LongGauge (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes) - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) -**** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.LongHistogram (not serializable) + +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes) + +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) +*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.LongHistogram (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes) - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) -**** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.LongUpDownCounter (not serializable) + +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes) + +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) +*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.LongUpDownCounter (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes) - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) + +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes) + +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleCounter.java index aa1523f220c..604a02248de 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleCounter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleCounter.java @@ -56,11 +56,6 @@ public void add(double increment) { add(increment, Attributes.empty()); } - @Override - public void remove(Attributes attributes) { - remove(attributes, Context.current()); - } - @Override public void remove(Attributes attributes, Context context) { storage.remove(attributes, context); diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleGauge.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleGauge.java index 9bb40073ffa..0ea8cc4036a 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleGauge.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleGauge.java @@ -43,11 +43,6 @@ public void set(double value) { set(value, Attributes.empty()); } - @Override - public void remove(Attributes attributes) { - remove(attributes, Context.current()); - } - @Override public void remove(Attributes attributes, Context context) { storage.remove(attributes, context); diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogram.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogram.java index b93edb8dc7f..e97a2e02be8 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogram.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogram.java @@ -56,11 +56,6 @@ public void record(double value) { record(value, Attributes.empty()); } - @Override - public void remove(Attributes attributes) { - remove(attributes, Context.current()); - } - @Override public void remove(Attributes attributes, Context context) { storage.remove(attributes, context); diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounter.java index 5d0948ea6d4..2467c27350f 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounter.java @@ -43,11 +43,6 @@ public void add(double increment) { add(increment, Attributes.empty()); } - @Override - public void remove(Attributes attributes) { - remove(attributes, Context.current()); - } - @Override public void remove(Attributes attributes, Context context) { storage.remove(attributes, context); diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongCounter.java index 53df6302e60..78e0a1a19cb 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongCounter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongCounter.java @@ -57,11 +57,6 @@ public void add(long increment) { add(increment, Attributes.empty()); } - @Override - public void remove(Attributes attributes) { - remove(attributes, Context.current()); - } - @Override public void remove(Attributes attributes, Context context) { storage.remove(attributes, context); diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongGauge.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongGauge.java index 187f4ca8add..bb1ae19b01e 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongGauge.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongGauge.java @@ -42,11 +42,6 @@ public void set(long value) { set(value, Attributes.empty()); } - @Override - public void remove(Attributes attributes) { - remove(attributes, Context.current()); - } - @Override public void remove(Attributes attributes, Context context) { storage.remove(attributes, context); diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongHistogram.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongHistogram.java index 8fde8702085..d0071adc635 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongHistogram.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongHistogram.java @@ -57,11 +57,6 @@ public void record(long value) { record(value, Attributes.empty()); } - @Override - public void remove(Attributes attributes) { - remove(attributes, Context.current()); - } - @Override public void remove(Attributes attributes, Context context) { storage.remove(attributes, context); diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounter.java index 130b3800815..afe3739db00 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounter.java @@ -43,11 +43,6 @@ public void add(long increment) { add(increment, Attributes.empty()); } - @Override - public void remove(Attributes attributes) { - remove(attributes, Context.current()); - } - @Override public void remove(Attributes attributes, Context context) { storage.remove(attributes, context); From eff27c4c1c25edb05c4218d8a14f5cf80442ac12 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Mon, 27 Oct 2025 20:41:01 -0700 Subject: [PATCH 3/7] spotless --- .../main/java/io/opentelemetry/api/metrics/DoubleCounter.java | 3 +-- .../main/java/io/opentelemetry/api/metrics/DoubleGauge.java | 2 -- .../java/io/opentelemetry/api/metrics/DoubleHistogram.java | 3 +-- .../java/io/opentelemetry/api/metrics/DoubleUpDownCounter.java | 3 +-- .../main/java/io/opentelemetry/api/metrics/LongCounter.java | 3 +-- .../src/main/java/io/opentelemetry/api/metrics/LongGauge.java | 3 +-- .../main/java/io/opentelemetry/api/metrics/LongHistogram.java | 3 +-- .../java/io/opentelemetry/api/metrics/LongUpDownCounter.java | 2 -- 8 files changed, 6 insertions(+), 16 deletions(-) diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleCounter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleCounter.java index 7279b0a369e..d3ff774f287 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleCounter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleCounter.java @@ -50,18 +50,17 @@ public interface DoubleCounter { * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. - * * @since 1.56.0 */ default void remove(Attributes attributes) { remove(attributes, Context.current()); } + /** * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. - * * @since 1.56.0 */ default void remove(Attributes attributes, Context context) {} diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleGauge.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleGauge.java index 3879ef524f2..23f894d44fb 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleGauge.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleGauge.java @@ -44,7 +44,6 @@ public interface DoubleGauge { * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. - * * @since 1.56.0 */ default void remove(Attributes attributes) { @@ -56,7 +55,6 @@ default void remove(Attributes attributes) { * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. - * * @since 1.56.0 */ default void remove(Attributes attributes, Context context) {} diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleHistogram.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleHistogram.java index d34c43e74ab..53c01ece944 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleHistogram.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleHistogram.java @@ -51,18 +51,17 @@ public interface DoubleHistogram { * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. - * * @since 1.56.0 */ default void remove(Attributes attributes) { remove(attributes, Context.current()); } + /** * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. - * * @since 1.56.0 */ default void remove(Attributes attributes, Context context) {} diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleUpDownCounter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleUpDownCounter.java index 75e64d9f224..34c2d10aef2 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleUpDownCounter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleUpDownCounter.java @@ -50,18 +50,17 @@ public interface DoubleUpDownCounter { * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. - * * @since 1.56.0 */ default void remove(Attributes attributes) { remove(attributes, Context.current()); } + /** * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. - * * @since 1.56.0 */ default void remove(Attributes attributes, Context context) {} diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/LongCounter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/LongCounter.java index 9b25854a7be..6b4ad84da1a 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/LongCounter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/LongCounter.java @@ -51,18 +51,17 @@ public interface LongCounter { * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. - * * @since 1.56.0 */ default void remove(Attributes attributes) { remove(attributes, Context.current()); } + /** * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. - * * @since 1.56.0 */ default void remove(Attributes attributes, Context context) {} diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/LongGauge.java b/api/all/src/main/java/io/opentelemetry/api/metrics/LongGauge.java index 4e99ae004fe..bc170566762 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/LongGauge.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/LongGauge.java @@ -44,18 +44,17 @@ public interface LongGauge { * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. - * * @since 1.56.0 */ default void remove(Attributes attributes) { remove(attributes, Context.current()); } + /** * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. - * * @since 1.56.0 */ default void remove(Attributes attributes, Context context) {} diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/LongHistogram.java b/api/all/src/main/java/io/opentelemetry/api/metrics/LongHistogram.java index e356cd14f42..71fe46ea161 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/LongHistogram.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/LongHistogram.java @@ -51,18 +51,17 @@ public interface LongHistogram { * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. - * * @since 1.56.0 */ default void remove(Attributes attributes) { remove(attributes, Context.current()); } + /** * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. - * * @since 1.56.0 */ default void remove(Attributes attributes, Context context) {} diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/LongUpDownCounter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/LongUpDownCounter.java index 1aebc461bc6..425c0fb0cbb 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/LongUpDownCounter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/LongUpDownCounter.java @@ -50,7 +50,6 @@ public interface LongUpDownCounter { * Remove the instrument. * * @param attributes A set of attributes to identify the instrument. - * * @since 1.56.0 */ default void remove(Attributes attributes) { @@ -62,7 +61,6 @@ default void remove(Attributes attributes) { * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. - * * @since 1.56.0 */ default void remove(Attributes attributes, Context context) {} From 4f2eda79fc254e38242f73dcb141acc8233e354b Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Mon, 27 Oct 2025 21:46:37 -0700 Subject: [PATCH 4/7] remove code --- .../api/metrics/DefaultMeter.java | 21 ---------------- .../metrics/ExtendedDefaultMeter.java | 24 ------------------- 2 files changed, 45 deletions(-) diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java index 0a2a36f9a50..4f72c0e3e06 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java @@ -75,9 +75,6 @@ public void add(long value, Attributes attributes) {} @Override public void add(long value) {} - - @Override - public void remove(Attributes attributes, Context context) {} } private static class NoopDoubleCounter implements DoubleCounter { @@ -90,8 +87,6 @@ public void add(double value, Attributes attributes) {} @Override public void add(double value) {} - @Override - public void remove(Attributes attributes, Context context) {} } private static class NoopLongCounterBuilder implements LongCounterBuilder { @@ -174,8 +169,6 @@ public void add(long value, Attributes attributes) {} @Override public void add(long value) {} - @Override - public void remove(Attributes attributes, Context context) {} } private static class NoopDoubleUpDownCounter implements DoubleUpDownCounter { @@ -188,8 +181,6 @@ public void add(double value, Attributes attributes) {} @Override public void add(double value) {} - @Override - public void remove(Attributes attributes, Context context) {} } private static class NoopLongUpDownCounterBuilder implements LongUpDownCounterBuilder { @@ -273,9 +264,6 @@ public void record(double value, Attributes attributes) {} @Override public void record(double value) {} - - @Override - public void remove(Attributes attributes, Context context) {} } private static class NoopLongHistogram implements LongHistogram { @@ -287,9 +275,6 @@ public void record(long value, Attributes attributes) {} @Override public void record(long value) {} - - @Override - public void remove(Attributes attributes, Context context) {} } private static class NoopDoubleHistogramBuilder implements DoubleHistogramBuilder { @@ -383,9 +368,6 @@ public void set(double value, Attributes attributes) {} @Override public void set(double value, Attributes attributes, Context context) {} - - @Override - public void remove(Attributes attributes, Context context) {} } private static class NoopLongGaugeBuilder implements LongGaugeBuilder { @@ -427,9 +409,6 @@ public void set(long value, Attributes attributes) {} @Override public void set(long value, Attributes attributes, Context context) {} - - @Override - public void remove(Attributes attributes, Context context) {} } private static class NoopObservableDoubleMeasurement implements ObservableDoubleMeasurement { diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/metrics/ExtendedDefaultMeter.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/metrics/ExtendedDefaultMeter.java index 0b1937b8f64..8283c7bb0b6 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/metrics/ExtendedDefaultMeter.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/metrics/ExtendedDefaultMeter.java @@ -107,9 +107,6 @@ public void add(long value, Attributes attributes) {} @Override public void add(long value) {} - - @Override - public void remove(Attributes attributes, Context context) {} } private static class NoopDoubleCounter implements ExtendedDoubleCounter { @@ -126,9 +123,6 @@ public void add(double value, Attributes attributes) {} @Override public void add(double value) {} - - @Override - public void remove(Attributes attributes, Context context) {} } private static class NoopLongCounterBuilder implements ExtendedLongCounterBuilder { @@ -215,9 +209,6 @@ public void add(long value, Attributes attributes) {} @Override public void add(long value) {} - - @Override - public void remove(Attributes attributes, Context context) {} } private static class NoopDoubleUpDownCounter implements ExtendedDoubleUpDownCounter { @@ -234,9 +225,6 @@ public void add(double value, Attributes attributes) {} @Override public void add(double value) {} - - @Override - public void remove(Attributes attributes, Context context) {} } private static class NoopLongUpDownCounterBuilder implements ExtendedLongUpDownCounterBuilder { @@ -326,9 +314,6 @@ public void record(double value, Attributes attributes) {} @Override public void record(double value) {} - - @Override - public void remove(Attributes attributes, Context context) {} } private static class NoopLongHistogram implements ExtendedLongHistogram { @@ -345,9 +330,6 @@ public void record(long value, Attributes attributes) {} @Override public void record(long value) {} - - @Override - public void remove(Attributes attributes, Context context) {} } private static class NoopDoubleHistogramBuilder implements ExtendedDoubleHistogramBuilder { @@ -446,9 +428,6 @@ public void set(double value, Attributes attributes) {} @Override public void set(double value, Attributes attributes, Context context) {} - - @Override - public void remove(Attributes attributes, Context context) {} } private static class NoopLongGaugeBuilder implements ExtendedLongGaugeBuilder { @@ -495,9 +474,6 @@ public void set(long value, Attributes attributes) {} @Override public void set(long value, Attributes attributes, Context context) {} - - @Override - public void remove(Attributes attributes, Context context) {} } private static class NoopObservableDoubleMeasurement implements ObservableDoubleMeasurement { From 061cde5038e4cd47047ed98762b51aad43ea46d9 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Mon, 27 Oct 2025 21:55:21 -0700 Subject: [PATCH 5/7] spotless --- .../main/java/io/opentelemetry/api/metrics/DefaultMeter.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java index 4f72c0e3e06..fff36ae9cbb 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java @@ -86,7 +86,6 @@ public void add(double value, Attributes attributes) {} @Override public void add(double value) {} - } private static class NoopLongCounterBuilder implements LongCounterBuilder { @@ -168,7 +167,6 @@ public void add(long value, Attributes attributes) {} @Override public void add(long value) {} - } private static class NoopDoubleUpDownCounter implements DoubleUpDownCounter { @@ -180,7 +178,6 @@ public void add(double value, Attributes attributes) {} @Override public void add(double value) {} - } private static class NoopLongUpDownCounterBuilder implements LongUpDownCounterBuilder { From 41fcb39be8d5a7cb66c165fe3bf8dea0845dd47e Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Mon, 27 Oct 2025 22:57:51 -0700 Subject: [PATCH 6/7] remove code and add test --- .../metrics/internal/state/EmptyMetricStorage.java | 3 --- .../internal/state/WriteableMetricStorage.java | 2 +- .../internal/state/MetricStorageRegistryTest.java | 3 --- .../state/SynchronousMetricStorageTest.java | 14 ++++++++++++++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/EmptyMetricStorage.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/EmptyMetricStorage.java index 5af10fee1a5..9a0ed207877 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/EmptyMetricStorage.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/EmptyMetricStorage.java @@ -40,9 +40,6 @@ public void recordLong(long value, Attributes attributes, Context context) {} @Override public void recordDouble(double value, Attributes attributes, Context context) {} - @Override - public void remove(Attributes attributes, Context context) {} - @Override public boolean isEnabled() { return false; diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/WriteableMetricStorage.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/WriteableMetricStorage.java index 61b562cbf51..d2225cf700e 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/WriteableMetricStorage.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/WriteableMetricStorage.java @@ -24,7 +24,7 @@ public interface WriteableMetricStorage { void recordDouble(double value, Attributes attributes, Context context); /** Remove a measurement. */ - void remove(Attributes attributes, Context context); + default void remove(Attributes attributes, Context context) {} /** * Returns {@code true} if the storage is actively recording measurements, and {@code false} diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/state/MetricStorageRegistryTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/state/MetricStorageRegistryTest.java index 563f6fa5cbe..9f91d13fe24 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/state/MetricStorageRegistryTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/state/MetricStorageRegistryTest.java @@ -115,9 +115,6 @@ public void recordLong(long value, Attributes attributes, Context context) {} @Override public void recordDouble(double value, Attributes attributes, Context context) {} - @Override - public void remove(Attributes attributes, Context context) {} - @Override public boolean isEnabled() { return true; diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/state/SynchronousMetricStorageTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/state/SynchronousMetricStorageTest.java index 354c1d899e5..5dcb6b34dea 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/state/SynchronousMetricStorageTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/state/SynchronousMetricStorageTest.java @@ -849,6 +849,20 @@ void enabledThenDisable_recordAndCollect(MemoryMode memoryMode) { storage.recordDouble(10d, Attributes.empty(), Context.current()); assertThat(storage.collect(RESOURCE, INSTRUMENTATION_SCOPE_INFO, 0, 10).isEmpty()).isTrue(); + + storage.remove(Attributes.empty(), Context.current()); + + storage.setEnabled(true); + + storage.recordDouble(10d, Attributes.empty(), Context.current()); + + storage.setEnabled(false); + + storage.remove(Attributes.empty(), Context.current()); + + storage.setEnabled(true); + + assertThat(storage.collect(RESOURCE, INSTRUMENTATION_SCOPE_INFO, 0, 10).isEmpty()).isFalse(); } @ParameterizedTest From 2a82801e8cfa4916889198eee39e55cc9d8924e4 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Mon, 16 Mar 2026 11:59:50 -0700 Subject: [PATCH 7/7] remove -> finish --- .../api/metrics/DoubleCounter.java | 10 +++--- .../api/metrics/DoubleGauge.java | 10 +++--- .../api/metrics/DoubleHistogram.java | 10 +++--- .../api/metrics/DoubleUpDownCounter.java | 10 +++--- .../api/metrics/LongCounter.java | 10 +++--- .../opentelemetry/api/metrics/LongGauge.java | 10 +++--- .../api/metrics/LongHistogram.java | 10 +++--- .../api/metrics/LongUpDownCounter.java | 10 +++--- .../current_vs_latest/opentelemetry-api.txt | 33 +++++++++--------- .../sdk/metrics/SdkDoubleCounter.java | 2 +- .../sdk/metrics/SdkDoubleGauge.java | 2 +- .../sdk/metrics/SdkDoubleHistogram.java | 2 +- .../sdk/metrics/SdkDoubleUpDownCounter.java | 2 +- .../sdk/metrics/SdkLongCounter.java | 2 +- .../sdk/metrics/SdkLongGauge.java | 2 +- .../sdk/metrics/SdkLongHistogram.java | 2 +- .../sdk/metrics/SdkLongUpDownCounter.java | 2 +- .../DefaultSynchronousMetricStorage.java | 34 ++++++++++++------- .../sdk/metrics/SdkDoubleCounterTest.java | 4 +-- .../sdk/metrics/SdkDoubleGaugeTest.java | 7 ++-- .../sdk/metrics/SdkDoubleHistogramTest.java | 5 ++- .../metrics/SdkDoubleUpDownCounterTest.java | 5 ++- .../sdk/metrics/SdkLongCounterTest.java | 4 +-- .../sdk/metrics/SdkLongGaugeTest.java | 6 ++-- .../sdk/metrics/SdkLongHistogramTest.java | 5 ++- .../sdk/metrics/SdkLongUpDownCounterTest.java | 5 ++- .../SdkObservableDoubleCounterTest.java | 2 +- .../SdkObservableDoubleUpDownCounterTest.java | 2 +- .../metrics/SdkObservableLongCounterTest.java | 2 +- .../SdkObservableLongUpDownCounterTest.java | 2 +- 30 files changed, 107 insertions(+), 105 deletions(-) diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleCounter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleCounter.java index d3ff774f287..4be299df91a 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleCounter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleCounter.java @@ -47,21 +47,21 @@ public interface DoubleCounter { void add(double value, Attributes attributes, Context context); /** - * Remove the instrument. + * Finish the instrument record. * * @param attributes A set of attributes to identify the instrument. * @since 1.56.0 */ - default void remove(Attributes attributes) { - remove(attributes, Context.current()); + default void finish(Attributes attributes) { + finish(attributes, Context.current()); } /** - * Remove the instrument. + * Finish the instrument record. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. * @since 1.56.0 */ - default void remove(Attributes attributes, Context context) {} + default void finish(Attributes attributes, Context context) {} } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleGauge.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleGauge.java index 23f894d44fb..73bfb709c83 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleGauge.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleGauge.java @@ -41,21 +41,21 @@ public interface DoubleGauge { void set(double value, Attributes attributes, Context context); /** - * Remove the instrument. + * Finish the instrument record. * * @param attributes A set of attributes to identify the instrument. * @since 1.56.0 */ - default void remove(Attributes attributes) { - remove(attributes, Context.current()); + default void finish(Attributes attributes) { + finish(attributes, Context.current()); } /** - * Remove the instrument. + * Finish the instrument record. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. * @since 1.56.0 */ - default void remove(Attributes attributes, Context context) {} + default void finish(Attributes attributes, Context context) {} } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleHistogram.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleHistogram.java index 53c01ece944..ec852e92cba 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleHistogram.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleHistogram.java @@ -48,21 +48,21 @@ public interface DoubleHistogram { void record(double value, Attributes attributes, Context context); /** - * Remove the instrument. + * Finish the instrument record. * * @param attributes A set of attributes to identify the instrument. * @since 1.56.0 */ - default void remove(Attributes attributes) { - remove(attributes, Context.current()); + default void finish(Attributes attributes) { + finish(attributes, Context.current()); } /** - * Remove the instrument. + * Finish the instrument record. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. * @since 1.56.0 */ - default void remove(Attributes attributes, Context context) {} + default void finish(Attributes attributes, Context context) {} } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleUpDownCounter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleUpDownCounter.java index 34c2d10aef2..49fcef437eb 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleUpDownCounter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/DoubleUpDownCounter.java @@ -47,21 +47,21 @@ public interface DoubleUpDownCounter { void add(double value, Attributes attributes, Context context); /** - * Remove the instrument. + * Finish the instrument record. * * @param attributes A set of attributes to identify the instrument. * @since 1.56.0 */ - default void remove(Attributes attributes) { - remove(attributes, Context.current()); + default void finish(Attributes attributes) { + finish(attributes, Context.current()); } /** - * Remove the instrument. + * Finish the instrument record. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. * @since 1.56.0 */ - default void remove(Attributes attributes, Context context) {} + default void finish(Attributes attributes, Context context) {} } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/LongCounter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/LongCounter.java index 6b4ad84da1a..0a8c21b594e 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/LongCounter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/LongCounter.java @@ -48,21 +48,21 @@ public interface LongCounter { void add(long value, Attributes attributes, Context context); /** - * Remove the instrument. + * Finish the instrument record. * * @param attributes A set of attributes to identify the instrument. * @since 1.56.0 */ - default void remove(Attributes attributes) { - remove(attributes, Context.current()); + default void finish(Attributes attributes) { + finish(attributes, Context.current()); } /** - * Remove the instrument. + * Finish the instrument record. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. * @since 1.56.0 */ - default void remove(Attributes attributes, Context context) {} + default void finish(Attributes attributes, Context context) {} } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/LongGauge.java b/api/all/src/main/java/io/opentelemetry/api/metrics/LongGauge.java index bc170566762..b450e51b23b 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/LongGauge.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/LongGauge.java @@ -41,21 +41,21 @@ public interface LongGauge { void set(long value, Attributes attributes, Context context); /** - * Remove the instrument. + * Finish the instrument record. * * @param attributes A set of attributes to identify the instrument. * @since 1.56.0 */ - default void remove(Attributes attributes) { - remove(attributes, Context.current()); + default void finish(Attributes attributes) { + finish(attributes, Context.current()); } /** - * Remove the instrument. + * Finish the instrument record. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. * @since 1.56.0 */ - default void remove(Attributes attributes, Context context) {} + default void finish(Attributes attributes, Context context) {} } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/LongHistogram.java b/api/all/src/main/java/io/opentelemetry/api/metrics/LongHistogram.java index 71fe46ea161..fd5dd6eb9ab 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/LongHistogram.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/LongHistogram.java @@ -48,21 +48,21 @@ public interface LongHistogram { void record(long value, Attributes attributes, Context context); /** - * Remove the instrument. + * Finish the instrument record. * * @param attributes A set of attributes to identify the instrument. * @since 1.56.0 */ - default void remove(Attributes attributes) { - remove(attributes, Context.current()); + default void finish(Attributes attributes) { + finish(attributes, Context.current()); } /** - * Remove the instrument. + * Finish the instrument record. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. * @since 1.56.0 */ - default void remove(Attributes attributes, Context context) {} + default void finish(Attributes attributes, Context context) {} } diff --git a/api/all/src/main/java/io/opentelemetry/api/metrics/LongUpDownCounter.java b/api/all/src/main/java/io/opentelemetry/api/metrics/LongUpDownCounter.java index 425c0fb0cbb..63cb42babd0 100644 --- a/api/all/src/main/java/io/opentelemetry/api/metrics/LongUpDownCounter.java +++ b/api/all/src/main/java/io/opentelemetry/api/metrics/LongUpDownCounter.java @@ -47,21 +47,21 @@ public interface LongUpDownCounter { void add(long value, Attributes attributes, Context context); /** - * Remove the instrument. + * Finish the instrument record. * * @param attributes A set of attributes to identify the instrument. * @since 1.56.0 */ - default void remove(Attributes attributes) { - remove(attributes, Context.current()); + default void finish(Attributes attributes) { + finish(attributes, Context.current()); } /** - * Remove the instrument. + * Finish the instrument record. * * @param attributes A set of attributes to identify the instrument. * @param context The explicit context to associate with this measurement. * @since 1.56.0 */ - default void remove(Attributes attributes, Context context) {} + default void finish(Attributes attributes, Context context) {} } diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-api.txt b/docs/apidiffs/current_vs_latest/opentelemetry-api.txt index 03451be5abe..2622662c1e9 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-api.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-api.txt @@ -1,34 +1,33 @@ Comparing source compatibility of opentelemetry-api-1.61.0-SNAPSHOT.jar against opentelemetry-api-1.60.1.jar -**** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.DoubleCounter (not serializable) *** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.DoubleCounter (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes) - +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) + +++ NEW METHOD: PUBLIC(+) void finish(io.opentelemetry.api.common.Attributes) + +++ NEW METHOD: PUBLIC(+) void finish(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) *** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.DoubleGauge (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes) - +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) + +++ NEW METHOD: PUBLIC(+) void finish(io.opentelemetry.api.common.Attributes) + +++ NEW METHOD: PUBLIC(+) void finish(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) *** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.DoubleHistogram (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes) - +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) + +++ NEW METHOD: PUBLIC(+) void finish(io.opentelemetry.api.common.Attributes) + +++ NEW METHOD: PUBLIC(+) void finish(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) *** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.DoubleUpDownCounter (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes) - +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) + +++ NEW METHOD: PUBLIC(+) void finish(io.opentelemetry.api.common.Attributes) + +++ NEW METHOD: PUBLIC(+) void finish(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) *** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.LongCounter (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes) - +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) + +++ NEW METHOD: PUBLIC(+) void finish(io.opentelemetry.api.common.Attributes) + +++ NEW METHOD: PUBLIC(+) void finish(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) *** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.LongGauge (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes) - +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) + +++ NEW METHOD: PUBLIC(+) void finish(io.opentelemetry.api.common.Attributes) + +++ NEW METHOD: PUBLIC(+) void finish(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) *** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.LongHistogram (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes) - +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) + +++ NEW METHOD: PUBLIC(+) void finish(io.opentelemetry.api.common.Attributes) + +++ NEW METHOD: PUBLIC(+) void finish(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) *** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.metrics.LongUpDownCounter (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes) - +++ NEW METHOD: PUBLIC(+) void remove(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) + +++ NEW METHOD: PUBLIC(+) void finish(io.opentelemetry.api.common.Attributes) + +++ NEW METHOD: PUBLIC(+) void finish(io.opentelemetry.api.common.Attributes, io.opentelemetry.context.Context) diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleCounter.java index 604a02248de..bb826cead1d 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleCounter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleCounter.java @@ -57,7 +57,7 @@ public void add(double increment) { } @Override - public void remove(Attributes attributes, Context context) { + public void finish(Attributes attributes, Context context) { storage.remove(attributes, context); } diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleGauge.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleGauge.java index 0ea8cc4036a..b5020f3d60c 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleGauge.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleGauge.java @@ -44,7 +44,7 @@ public void set(double value) { } @Override - public void remove(Attributes attributes, Context context) { + public void finish(Attributes attributes, Context context) { storage.remove(attributes, context); } diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogram.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogram.java index e97a2e02be8..fadfcf530e6 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogram.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogram.java @@ -57,7 +57,7 @@ public void record(double value) { } @Override - public void remove(Attributes attributes, Context context) { + public void finish(Attributes attributes, Context context) { storage.remove(attributes, context); } diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounter.java index 2467c27350f..e66e8e77f90 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounter.java @@ -44,7 +44,7 @@ public void add(double increment) { } @Override - public void remove(Attributes attributes, Context context) { + public void finish(Attributes attributes, Context context) { storage.remove(attributes, context); } diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongCounter.java index 78e0a1a19cb..c98ed9eb929 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongCounter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongCounter.java @@ -58,7 +58,7 @@ public void add(long increment) { } @Override - public void remove(Attributes attributes, Context context) { + public void finish(Attributes attributes, Context context) { storage.remove(attributes, context); } diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongGauge.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongGauge.java index bb1ae19b01e..f68a8461272 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongGauge.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongGauge.java @@ -43,7 +43,7 @@ public void set(long value) { } @Override - public void remove(Attributes attributes, Context context) { + public void finish(Attributes attributes, Context context) { storage.remove(attributes, context); } diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongHistogram.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongHistogram.java index d0071adc635..24c0031a575 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongHistogram.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongHistogram.java @@ -58,7 +58,7 @@ public void record(long value) { } @Override - public void remove(Attributes attributes, Context context) { + public void finish(Attributes attributes, Context context) { storage.remove(attributes, context); } diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounter.java index afe3739db00..67f0b6fb6a6 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounter.java @@ -44,7 +44,7 @@ public void add(long increment) { } @Override - public void remove(Attributes attributes, Context context) { + public void finish(Attributes attributes, Context context) { storage.remove(attributes, context); } diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/DefaultSynchronousMetricStorage.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/DefaultSynchronousMetricStorage.java index bb1eb7ead9c..4d17bda60ec 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/DefaultSynchronousMetricStorage.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/DefaultSynchronousMetricStorage.java @@ -124,19 +124,6 @@ public void recordDouble(double value, Attributes attributes, Context context) { abstract void doRecordDouble(double value, Attributes attributes, Context context); - @Override - public void remove(Attributes attributes, Context context) { - if (!enabled) { - return; - } - AggregatorHolder aggregatorHolder = getHolderForRecord(); - try { - aggregatorHolder.aggregatorHandles.remove(attributes); - } finally { - releaseHolderForRecord(aggregatorHolder); - } - } - @Override public void setEnabled(boolean enabled) { this.enabled = enabled; @@ -237,6 +224,19 @@ void doRecordDouble(double value, Attributes attributes, Context context) { } } + @Override + public void remove(Attributes attributes, Context context) { + if (!enabled) { + return; + } + AggregatorHolder holderForRecord = getHolderForRecord(); + try { + holderForRecord.aggregatorHandles.remove(attributes); + } finally { + releaseHolderForRecord(holderForRecord); + } + } + @Nullable @Override AggregatorHandle maybeGetPooledAggregatorHandle() { @@ -434,6 +434,14 @@ void doRecordDouble(double value, Attributes attributes, Context context) { .recordDouble(value, attributes, context); } + @Override + public void remove(Attributes attributes, Context context) { + if (!enabled) { + return; + } + aggregatorHandles.remove(attributes); + } + @Nullable @Override AggregatorHandle maybeGetPooledAggregatorHandle() { diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleCounterTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleCounterTest.java index f45d996df41..e580c8b901e 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleCounterTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleCounterTest.java @@ -58,11 +58,11 @@ void collectMetrics_NoRecords() { } @Test - void collectMetrics_Remove() { + void collectMetrics_finish() { DoubleCounter counter = sdkMeter.counterBuilder("testCounter").ofDoubles().build(); Attributes attrs = Attributes.of(stringKey("key"), "value"); counter.add(1, attrs); - counter.remove(attrs); + counter.finish(attrs); assertThat(sdkMeterReader.collectAllMetrics()).isEmpty(); } diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleGaugeTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleGaugeTest.java index 52ffaa5b5d1..673b1ed605e 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleGaugeTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleGaugeTest.java @@ -27,7 +27,6 @@ import io.opentelemetry.sdk.trace.SdkTracerProvider; import java.time.Duration; import java.util.Collections; -import java.util.stream.IntStream; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; @@ -66,7 +65,7 @@ void set_NaN() { } @Test - void observable_RemoveCallback() { + void observable_finishCallback() { ObservableDoubleGauge gauge = sdkMeter.gaugeBuilder("testGauge").buildWithCallback(measurement -> measurement.record(10)); @@ -99,12 +98,12 @@ void collectMetrics_NoRecords() { } @Test - void collectMetrics_Remove() { + void collectMetrics_finish() { DoubleGauge gauge = sdkMeter.gaugeBuilder("testGauge").build(); assertThat(cumulativeReader.collectAllMetrics()).isEmpty(); Attributes attrs = Attributes.of(stringKey("key"), "value"); gauge.set(1, attrs); - gauge.remove(attrs); + gauge.finish(attrs); Assertions.assertThat(cumulativeReader.collectAllMetrics()).isEmpty(); } diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogramTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogramTest.java index f7bd1e8e040..645869a6b35 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogramTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogramTest.java @@ -27,7 +27,6 @@ import java.time.Duration; import java.util.Arrays; import java.util.Collections; -import java.util.stream.IntStream; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -66,11 +65,11 @@ void collectMetrics_NoRecords() { } @Test - void collectMetrics_Remove() { + void collectMetrics_finish() { DoubleHistogram histogram = sdkMeter.histogramBuilder("testHistogram").build(); Attributes attrs = Attributes.of(stringKey("key"), "value"); histogram.record(1, attrs); - histogram.remove(attrs); + histogram.finish(attrs); Assertions.assertThat(sdkMeterReader.collectAllMetrics()).isEmpty(); } diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounterTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounterTest.java index 5a4307dd8d9..49daa3def39 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounterTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounterTest.java @@ -18,7 +18,6 @@ import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.sdk.testing.time.TestClock; import java.time.Duration; -import java.util.stream.IntStream; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; @@ -59,12 +58,12 @@ void collectMetrics_NoRecords() { } @Test - void collectMetrics_Remove() { + void collectMetrics_finish() { DoubleUpDownCounter counter = sdkMeter.upDownCounterBuilder("testUpDownCounter").ofDoubles().build(); Attributes attrs = Attributes.of(stringKey("key"), "value"); counter.add(1, attrs); - counter.remove(attrs); + counter.finish(attrs); Assertions.assertThat(sdkMeterReader.collectAllMetrics()).isEmpty(); } diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongCounterTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongCounterTest.java index a4a4d590c43..a437bc5a406 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongCounterTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongCounterTest.java @@ -56,11 +56,11 @@ void collectMetrics_NoRecords() { } @Test - void collectMetrics_Remove() { + void collectMetrics_finish() { LongCounter counter = sdkMeter.counterBuilder("Counter").build(); Attributes attrs = Attributes.of(stringKey("key"), "value"); counter.add(1, attrs); - counter.remove(attrs); + counter.finish(attrs); assertThat(sdkMeterReader.collectAllMetrics()).isEmpty(); } diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongGaugeTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongGaugeTest.java index fdeb4c7d564..9f5dbef9833 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongGaugeTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongGaugeTest.java @@ -54,7 +54,7 @@ void set_PreventNullAttributes() { } @Test - void observable_RemoveCallback() { + void observable_finishCallback() { ObservableLongGauge gauge = sdkMeter .gaugeBuilder("testGauge") @@ -81,12 +81,12 @@ void collectMetrics_NoRecords() { } @Test - void collectMetrics_Remove() { + void collectMetrics_finish() { LongGauge gauge = sdkMeter.gaugeBuilder("testGauge").ofLongs().build(); assertThat(cumulativeReader.collectAllMetrics()).isEmpty(); Attributes attrs = Attributes.of(stringKey("key"), "value"); gauge.set(1, attrs); - gauge.remove(attrs); + gauge.finish(attrs); Assertions.assertThat(cumulativeReader.collectAllMetrics()).isEmpty(); } diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongHistogramTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongHistogramTest.java index 7b42c2149d6..9d206d14aab 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongHistogramTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongHistogramTest.java @@ -26,7 +26,6 @@ import java.time.Duration; import java.util.Arrays; import java.util.Collections; -import java.util.stream.IntStream; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -65,11 +64,11 @@ void collectMetrics_NoRecords() { } @Test - void collectMetrics_Remove() { + void collectMetrics_finish() { LongHistogram histogram = sdkMeter.histogramBuilder("testHistogram").ofLongs().build(); Attributes attrs = Attributes.of(stringKey("key"), "value"); histogram.record(1, attrs); - histogram.remove(attrs); + histogram.finish(attrs); Assertions.assertThat(reader.collectAllMetrics()).isEmpty(); } diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounterTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounterTest.java index 3e9770a2758..e9dc9b05b3d 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounterTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounterTest.java @@ -18,7 +18,6 @@ import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.sdk.testing.time.TestClock; import java.time.Duration; -import java.util.stream.IntStream; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; @@ -53,11 +52,11 @@ void collectMetrics_NoRecords() { } @Test - void collectMetrics_Remove() { + void collectMetrics_finish() { LongUpDownCounter counter = sdkMeter.upDownCounterBuilder("testUpDownCounter").build(); Attributes attrs = Attributes.of(stringKey("key"), "value"); counter.add(1, attrs); - counter.remove(attrs); + counter.finish(attrs); Assertions.assertThat(sdkMeterReader.collectAllMetrics()).isEmpty(); } diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkObservableDoubleCounterTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkObservableDoubleCounterTest.java index cc1c887bf3a..8e7507d6b22 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkObservableDoubleCounterTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkObservableDoubleCounterTest.java @@ -33,7 +33,7 @@ class SdkObservableDoubleCounterTest { SdkMeterProvider.builder().setClock(testClock).setResource(RESOURCE); @Test - void removeCallback() { + void finishCallback() { InMemoryMetricReader sdkMeterReader = InMemoryMetricReader.create(); ObservableDoubleCounter counter = sdkMeterProviderBuilder diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkObservableDoubleUpDownCounterTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkObservableDoubleUpDownCounterTest.java index 8b212220093..22c3c4734d2 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkObservableDoubleUpDownCounterTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkObservableDoubleUpDownCounterTest.java @@ -35,7 +35,7 @@ class SdkObservableDoubleUpDownCounterTest { SdkMeterProvider.builder().setClock(testClock).setResource(RESOURCE); @Test - void removeCallback() { + void finishCallback() { InMemoryMetricReader sdkMeterReader = InMemoryMetricReader.create(); ObservableDoubleUpDownCounter counter = sdkMeterProviderBuilder diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkObservableLongCounterTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkObservableLongCounterTest.java index f4208b1c26d..cd71bb4c34c 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkObservableLongCounterTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkObservableLongCounterTest.java @@ -30,7 +30,7 @@ class SdkObservableLongCounterTest { SdkMeterProvider.builder().setClock(testClock).setResource(RESOURCE); @Test - void removeCallback() { + void finishCallback() { InMemoryMetricReader sdkMeterReader = InMemoryMetricReader.create(); ObservableLongCounter counter = sdkMeterProviderBuilder diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkObservableLongUpDownCounterTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkObservableLongUpDownCounterTest.java index 33c3c17167d..b972f059e5e 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkObservableLongUpDownCounterTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/SdkObservableLongUpDownCounterTest.java @@ -30,7 +30,7 @@ class SdkObservableLongUpDownCounterTest { SdkMeterProvider.builder().setClock(testClock).setResource(RESOURCE); @Test - void removeCallback() { + void finishCallback() { InMemoryMetricReader sdkMeterReader = InMemoryMetricReader.create(); ObservableLongUpDownCounter counter = sdkMeterProviderBuilder