Skip to content

Allow to unregister/stop/destroy metric instruments #4013

@mateuszrzeszutek

Description

@mateuszrzeszutek

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions