Skip to content

Commit

Permalink
Add example for sync gauge in Go (#4610)
Browse files Browse the repository at this point in the history
Co-authored-by: Phillip Carter <[email protected]>
  • Loading branch information
bagmeg and cartermp authored Jun 7, 2024
1 parent f1d96cb commit a17411c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions content/en/docs/languages/go/instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,35 @@ func removeItem() {
}
```

### Using Gauges

Gauges are used to measure non-additive values when changes occur.

For example, here's how you might report the current speed of a CPU fan:

```go
import (
"net/http"

"go.opentelemetry.io/otel/metric"
)

func init() {
speedGauge, err := meter.Int64Gauge(
"cpu.fan.speed",
metric.WithDescription("Speed of CPU fan"),
metric.WithUnit("RPM"),
)
if err != nil {
panic(err)
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// hard-code 1500 RPM for demonstrative purposes
speedGauge.Record(r.Context(), 1500)
})
}
```

### Using Histograms

Histograms are used to measure a distribution of values over time.
Expand Down

0 comments on commit a17411c

Please sign in to comment.