Skip to content

Commit

Permalink
handle err in metric example test (#4462)
Browse files Browse the repository at this point in the history
* fix type in metric example test

Signed-off-by: Pulak Kanti Bhowmick <pkbhowmick007@gmail.com>

* handle error in metric example test

Signed-off-by: Pulak Kanti Bhowmick <pkbhowmick007@gmail.com>

* update counter example

Signed-off-by: Pulak Kanti Bhowmick <pkbhowmick007@gmail.com>

* handle the err only

Signed-off-by: Pulak Kanti Bhowmick <pkbhowmick007@gmail.com>

---------

Signed-off-by: Pulak Kanti Bhowmick <pkbhowmick007@gmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
pkbhowmick and MrAlias committed Aug 28, 2023
1 parent 3c476ce commit f172db8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions metric/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,18 @@ func ExampleMeter_asynchronous_multiple() {
meter := otel.Meter("go.opentelemetry.io/otel/metric#MultiAsyncExample")

// This is just a sample of memory stats to record from the Memstats
heapAlloc, _ := meter.Int64ObservableUpDownCounter("heapAllocs")
gcCount, _ := meter.Int64ObservableCounter("gcCount")
heapAlloc, err := meter.Int64ObservableUpDownCounter("heapAllocs")
if err != nil {
fmt.Println("failed to register updown counter for heapAllocs")
panic(err)
}
gcCount, err := meter.Int64ObservableCounter("gcCount")
if err != nil {
fmt.Println("failed to register counter for gcCount")
panic(err)
}

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

0 comments on commit f172db8

Please sign in to comment.