From 88ac0e9152d6a3d7234a41c205657fc2e481430d Mon Sep 17 00:00:00 2001 From: joonsoo park Date: Thu, 6 Jun 2024 08:46:01 +0000 Subject: [PATCH 1/2] add example for sync gauge in Go --- .../en/docs/languages/go/instrumentation.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/content/en/docs/languages/go/instrumentation.md b/content/en/docs/languages/go/instrumentation.md index c9b61dc8ddbe..5163da55e616 100644 --- a/content/en/docs/languages/go/instrumentation.md +++ b/content/en/docs/languages/go/instrumentation.md @@ -534,6 +534,34 @@ func removeItem() { } ``` +### Using Gauges + +Gauges are used to measure non-additive values when changes occur. + +For example, here's how you report the 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) { + speedGauge.Record(r.Context(), 1500) + }) +} +``` + ### Using Histograms Histograms are used to measure a distribution of values over time. From 353d795a9982c3f37cc12af5dd3eebe7b10c4035 Mon Sep 17 00:00:00 2001 From: joonsoo park Date: Thu, 6 Jun 2024 13:43:48 +0000 Subject: [PATCH 2/2] apply suggestions from PR review - Changed gauge explanation - Added comment --- content/en/docs/languages/go/instrumentation.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/en/docs/languages/go/instrumentation.md b/content/en/docs/languages/go/instrumentation.md index 5163da55e616..873614be8594 100644 --- a/content/en/docs/languages/go/instrumentation.md +++ b/content/en/docs/languages/go/instrumentation.md @@ -538,7 +538,7 @@ func removeItem() { Gauges are used to measure non-additive values when changes occur. -For example, here's how you report the speed of a CPU fan: +For example, here's how you might report the current speed of a CPU fan: ```go import ( @@ -557,6 +557,7 @@ func init() { panic(err) } http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + // hard-code 1500 RPM for demonstrative purposes speedGauge.Record(r.Context(), 1500) }) }