Skip to content

Commit a17411c

Browse files
bagmegcartermp
andauthored
Add example for sync gauge in Go (#4610)
Co-authored-by: Phillip Carter <[email protected]>
1 parent f1d96cb commit a17411c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

content/en/docs/languages/go/instrumentation.md

+29
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,35 @@ func removeItem() {
534534
}
535535
```
536536

537+
### Using Gauges
538+
539+
Gauges are used to measure non-additive values when changes occur.
540+
541+
For example, here's how you might report the current speed of a CPU fan:
542+
543+
```go
544+
import (
545+
"net/http"
546+
547+
"go.opentelemetry.io/otel/metric"
548+
)
549+
550+
func init() {
551+
speedGauge, err := meter.Int64Gauge(
552+
"cpu.fan.speed",
553+
metric.WithDescription("Speed of CPU fan"),
554+
metric.WithUnit("RPM"),
555+
)
556+
if err != nil {
557+
panic(err)
558+
}
559+
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
560+
// hard-code 1500 RPM for demonstrative purposes
561+
speedGauge.Record(r.Context(), 1500)
562+
})
563+
}
564+
```
565+
537566
### Using Histograms
538567

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

0 commit comments

Comments
 (0)