Skip to content

metrics: improve ObservableInstrument API #65

@inge4pres

Description

@inge4pres

Describe the current state

#63 introduced Asynchronous Instruments.
Those are collected in Meter as "ObservableXXX" instrument types and dispatched to the right implementation under Instrument.

As initially introduced in the PR, the DX to consume these instrument is a little weird because users aren't expected to consume the returned instance of any ObservableInstrument.

Only Meter should access them: they'll be "scraped" when MetricReader collects data from the Meter, invoking their callbacks through measurementsData.
The only operation that should be user-facing is managing callbacks.
While we have a registerCallback method on each Async Instrument, we don't have a way to un-register callbacks, which is indicated in the OTel spec.

Describe the desired state

To simplify and improve the way Async Instruments are consumed, I think we have 2 options:

  1. remove entirely the return type from Meter.createObservableXYZ: this makes the Async Instrument inaccessible outside of the Meter
  2. change the design, treat the Observable Instruments as separate from Instrument

Whichever is taken, a functionality to remove callbacks from Async Instrument should be planned and added.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions