opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

Add Synchronous Gauge instrument to the metrics API

Open karlbohlmark opened this issue 2 years ago • 5 comments
trafficstars

This is a recent addition: https://github.com/open-telemetry/opentelemetry-specification/pull/3540

https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#gauge

karlbohlmark avatar Nov 15 '23 17:11 karlbohlmark

Hey @pichlermarc, is this up for grabs? I can take this up. I think the implementation could look similar to other SyncInstruments?

export class GaugeInstrument extends SyncInstrument implements Gauge {
  record(value: number, attributes?: MetricAttributes, ctx?: Context): void {
    this._record(value, attributes, ctx);
  }
}

mohitk05 avatar Jan 17 '24 17:01 mohitk05

It's yours @mohitk05 :slightly_smiling_face:

Yes, implementation would look similar, however, you'll need to duplicate the (currently non-existent) Gauge interface in the SDK as we can't use types that are not available in earlier API versions. The SDK is backwards compatible with the API, so it can't use any types that were added after its initial release.

pichlermarc avatar Jan 23 '24 17:01 pichlermarc

Anyone know of a workaround for now?

fordneild avatar Feb 27 '24 18:02 fordneild

Anyone know of a workaround for now?

Using an UpDownCounter and registering a view with a LastValueAggregation (see https://opentelemetry.io/docs/languages/js/instrumentation/#configure-metric-views, it does not show that example implicitly, but similar to the histogram one, except you're adding new LastValueAggregation() as the aggregation)

pichlermarc avatar Feb 28 '24 13:02 pichlermarc

Apologies for the delay here, seems like @clintonb has implemented this. Please assign them/close the issue as required.

mohitk05 avatar Apr 12 '24 08:04 mohitk05