From d3f4d8cfe57c4435ad9a5d4f39ecec9bc715023e Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Sat, 25 Oct 2025 01:07:04 -0700 Subject: [PATCH 1/6] 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 | 11 +++++ .../sdk/metrics/SdkDoubleHistogramTest.java | 10 ++++ .../metrics/SdkDoubleUpDownCounterTest.java | 11 +++++ .../sdk/metrics/SdkLongCounterTest.java | 9 ++++ .../sdk/metrics/SdkLongGaugeTest.java | 10 ++++ .../sdk/metrics/SdkLongHistogramTest.java | 10 ++++ .../sdk/metrics/SdkLongUpDownCounterTest.java | 10 ++++ .../state/MetricStorageRegistryTest.java | 3 ++ 32 files changed, 437 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 ba34d454891..7446b5cb4eb 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.56.0-SNAPSHOT.jar against opentelemetry-api-1.55.0.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 7fd6e435556..f3498ad372b 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 de4473ace2e..f5be5713e33 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 0de901060f5..c9c3c07d997 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 b777ad34e59..e47dac64586 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 ba00c3dc5c6..ffc69ce7089 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 @@ -140,6 +140,19 @@ public void recordDouble(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 d733821972b..eebd87756a8 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,6 +58,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 61c0d3ad0b9..5132a5acf87 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 @@ -28,6 +28,7 @@ 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}. */ @@ -97,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 dd210faad46..26577b1152f 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 @@ -28,6 +28,7 @@ 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; @@ -64,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 a8dc0041c0d..0597060f75f 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 @@ -19,6 +19,7 @@ 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}. */ @@ -57,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 30f9c27ff22..ea271128987 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,6 +56,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 0a117e48d82..9ee7a341e6f 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 @@ -81,6 +81,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 dd802ff613f..ae3290f649a 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 @@ -27,6 +27,7 @@ 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 +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 50feee13094..738b00bdf93 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 @@ -19,6 +19,7 @@ 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}. */ @@ -51,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 161af145047a78932063bacbe2fa3eb55f51e514 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Mon, 27 Oct 2025 16:26:02 -0700 Subject: [PATCH 2/6] 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 | 48 +++++++++---------- .../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(+), 134 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 7446b5cb4eb..88e93eed18a 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-api.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-api.txt @@ -1,33 +1,33 @@ Comparing source compatibility of opentelemetry-api-1.56.0-SNAPSHOT.jar against opentelemetry-api-1.55.0.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 f3498ad372b..ae8f4407b7c 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 f5be5713e33..e9b887fc2de 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 c9c3c07d997..93e6a0b945f 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 e47dac64586..d0af58ac965 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 b55b8a7296b880939ff9213d40415495c0bc3fb1 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Mon, 27 Oct 2025 20:41:01 -0700 Subject: [PATCH 3/6] 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 601808e0d94c5b9241a25d13390330f4e48b09ae Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Mon, 27 Oct 2025 21:46:37 -0700 Subject: [PATCH 4/6] 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 2b7031186fff500d4ea3ff9a4aff0cbf30374833 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Mon, 27 Oct 2025 21:55:21 -0700 Subject: [PATCH 5/6] 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 0d7ab3806b0602a0a7497f7835e10ccd38aae665 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Mon, 27 Oct 2025 22:57:51 -0700 Subject: [PATCH 6/6] 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 e79f3ad9718..2e6dab2cfc5 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 @@ -923,6 +923,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