-
Notifications
You must be signed in to change notification settings - Fork 958
Allow to unregister/stop/destroy metric instruments #4013
Description
Is your feature request related to a problem? Please describe.
Currently there is no way to stop/remove an instrument after it is created (see open-telemetry/opentelemetry-specification#2232 for more details). This is a major difference when you compare OTel metrics API to Dropwizard or Micrometer, both of which allow removing instruments.
Describe the solution you'd like
For synchronous instruments we could just add a stop() (the name being whatever the spec decides) method to the interfaces representing each synchronous instrument.
Things get a bit more complicated with asynchronous instruments - right now buildWithCallback() methods return void, there's no object/concept in the API that would represent an already started async instrument. In case the spec issue is not resolved before metrics API going stable it will be pretty difficult to offer forward compatibility. How about we add initially empty interfaces for all async instruments and return them in buildWithCallback methods:
interface ObservableLongCounter {
}
// ...
interface LongCounterBuilder {
ObservableLongCounter buildWithCallback(Consumer<ObservableLongMeasurement> callback);
}Then we could just add methods to ObservableLongCounter in a forward-compatible manner once the spec issue is fixed.
Additional context
open-telemetry/opentelemetry-specification#2232
open-telemetry/opentelemetry-java-instrumentation#4919