Skip to content

Commit

Permalink
fix: gauge continuity (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
fracasula committed May 23, 2023
1 parent 458288a commit 698f566
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions stats/otel_measurement.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package stats

import (
"context"
"sync"
"sync/atomic"
"time"

"go.opentelemetry.io/otel/attribute"
Expand Down Expand Up @@ -38,29 +38,22 @@ func (c *otelCounter) Increment() {
// otelGauge represents a gauge stat
type otelGauge struct {
*otelMeasurement
value interface{}
valueMu sync.Mutex
value atomic.Value
}

// Gauge records an absolute value for this stat. Only applies to GaugeType stats
func (g *otelGauge) Gauge(value interface{}) {
if g.disabled {
return
}
g.valueMu.Lock()
g.value = value
g.valueMu.Unlock()
g.value.Store(value)
}

func (g *otelGauge) getValue() interface{} {
if g.disabled {
return nil
}
g.valueMu.Lock()
v := g.value
g.value = nil
g.valueMu.Unlock()
return v
return g.value.Load()
}

// otelTimer represents a timer stat
Expand Down

0 comments on commit 698f566

Please sign in to comment.