Skip to content

Commit

Permalink
Fix metric API example_test
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Jan 11, 2023
1 parent 6df31fa commit 7ad9845
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions metric/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,21 @@ func ExampleMeter_asynchronous_multiple() {
gcCount, _ := meter.Int64ObservableCounter("gcCount")
gcPause, _ := meter.Float64Histogram("gcPause")

_, err := meter.RegisterCallback([]instrument.Asynchronous{
heapAlloc,
gcCount,
},
func(ctx context.Context) error {
_, err := meter.RegisterCallback(
func(ctx context.Context, o metric.ObservationRecorder) error {
memStats := &runtime.MemStats{}
// This call does work
runtime.ReadMemStats(memStats)

heapAlloc.Observe(ctx, int64(memStats.HeapAlloc))
gcCount.Observe(ctx, int64(memStats.NumGC))
o.Int64(heapAlloc, int64(memStats.HeapAlloc))
o.Int64(gcCount, int64(memStats.NumGC))

// This function synchronously records the pauses
computeGCPauses(ctx, gcPause, memStats.PauseNs[:])
return nil
},
heapAlloc,
gcCount,
)

if err != nil {
Expand Down

0 comments on commit 7ad9845

Please sign in to comment.