Skip to content

Commit

Permalink
Migrate to OTEL synchronous Float64Gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
olegbespalov committed Sep 2, 2024
1 parent 36c3be2 commit 1893f39
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 79 deletions.
67 changes: 0 additions & 67 deletions pkg/opentelemetry/gauge.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/opentelemetry/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (o *Output) dispatch(entry metrics.Sample) error {
return err
}

gauge.Set(entry.Value, attributeSet)
gauge.Record(ctx, entry.Value, attributeSetOpt)
case metrics.Trend:
trend, err := o.metricsRegistry.getOrCreateHistogram(name, unit)
if err != nil {
Expand Down
17 changes: 6 additions & 11 deletions pkg/opentelemetry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,32 +125,27 @@ func (r *registry) getOrCreateCountersForRate(name string) (otelMetric.Int64Coun
return nonZeroCounter, totalCounter, nil
}

func (r *registry) getOrCreateGauge(name, unit string) (*Float64Gauge, error) {
func (r *registry) getOrCreateGauge(name, unit string) (otelMetric.Float64Gauge, error) {
if gauge, ok := r.gauges.Load(name); ok {
if v, ok := gauge.(*Float64Gauge); ok {
if v, ok := gauge.(otelMetric.Float64Gauge); ok {
return v, nil
}

return nil, fmt.Errorf("metric %q is not a gauge", name)
}

g := NewFloat64Gauge()

opts := []otelMetric.Float64ObservableGaugeOption{
otelMetric.WithFloat64Callback(g.Callback),
}

opts := []otelMetric.Float64GaugeOption{}
if unit != "" {
opts = append(opts, otelMetric.WithUnit(unit))
}

_, err := r.meter.Float64ObservableGauge(name, opts...)
gauge, err := r.meter.Float64Gauge(name, opts...)
if err != nil {
return nil, fmt.Errorf("failed to create gauge for %q: %w", name, err)
}

r.logger.Debugf("registered gauge metric %q ", name)

r.gauges.Store(name, g)
return g, nil
r.gauges.Store(name, gauge)
return gauge, nil
}

0 comments on commit 1893f39

Please sign in to comment.