Skip to content

Commit

Permalink
Remove the sync inst from async example (#4019)
Browse files Browse the repository at this point in the history
Simplify the ExampleMeter_asynchronous_multiple example test to only
include asynchronous instruments. Remove the synchronous histogram.
  • Loading branch information
MrAlias authored Apr 20, 2023
1 parent c5e2799 commit 002444a
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions metric/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,16 @@ func ExampleMeter_asynchronous_multiple() {
// This is just a sample of memory stats to record from the Memstats
heapAlloc, _ := meter.Int64ObservableUpDownCounter("heapAllocs")
gcCount, _ := meter.Int64ObservableCounter("gcCount")
gcPause, _ := meter.Float64Histogram("gcPause")

_, err := meter.RegisterCallback(
func(ctx context.Context, o metric.Observer) error {
func(_ context.Context, o metric.Observer) error {
memStats := &runtime.MemStats{}
// This call does work
runtime.ReadMemStats(memStats)

o.ObserveInt64(heapAlloc, int64(memStats.HeapAlloc))
o.ObserveInt64(gcCount, int64(memStats.NumGC))

// This function synchronously records the pauses
computeGCPauses(ctx, gcPause, memStats.PauseNs[:])
return nil
},
heapAlloc,
Expand All @@ -102,6 +99,3 @@ func ExampleMeter_asynchronous_multiple() {
panic(err)
}
}

// This is just an example, see the the contrib runtime instrumentation for real implementation.
func computeGCPauses(ctx context.Context, recorder instrument.Float64Histogram, pauseBuff []uint64) {}

0 comments on commit 002444a

Please sign in to comment.