Skip to content

A mechanism for updating multiple ObservableIntruments in one callback #3653

@KJTsanaktsidis

Description

@KJTsanaktsidis

Is your feature request related to a problem?
I'm writing a program that uses a custom hardware device, and I'd like to get metrics off that hardware device and into our OpenTelemetry-based observability stack. The hardware reports several metrics values of interest in one operation; i.e. it basically exposes a "get a bunch of telemetry" function.

We're using PeriodicExportingMetricReader to send telemetry to our OpenTelemetry collector every 30 seconds. Because of this, I'd ideally like to use observable counters/gauges, so that the values collected are as fresh as possible before they're exported.

The problem is, it doesn't really make sense to register N-many observable instruments for each value exposed by our hardware; there is no way to get telemetry off the device other than reading it all at once, so each callback would have to collect the entire telemetry package independently. This is rather wasteful!

Describe the solution you'd like

  • Either some way to register a single callback which will be called once per collection cycle for multiple different observable instruments (receiving them all as an array argument, perhaps), or
  • A way to run arbitrary user-provided callbacks not attached to any instrument to be executed in Meter::Collect (such a callback could be used to update a bunch of synchronous instruments all at once), or
  • Somebody to pat me on the shoulder, and say what I'm doing to hack around this at the moment is Fine Actually.

Describe alternatives you've considered
My current workaround involves registering a "dummy" Observable instrument, and inside the callback for that I poll the hardware for telemetry and then record metrics from that into synchronous counters & gauges.

Additional context
Happy to send a PR if we can land on a desired behavour!

Tip: React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage/acceptedIndicates an issue or PR is ready to be actively worked on.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions