Skip to content

Commit

Permalink
sdk/metric: Update package example (#4540)
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared authored Sep 22, 2023
1 parent 206ed55 commit 10b9f90
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions sdk/metric/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ import (
//
// Here's how you might initialize a metrics provider.
func Example() {
// See [go.opentelemetry.io/otel/sdk/resource] for more
// information about how to create and use resources.
// Create resource.
res, err := resource.Merge(resource.Default(),
resource.NewWithAttributes(semconv.SchemaURL,
semconv.ServiceName("my-service"),
Expand All @@ -46,8 +45,8 @@ func Example() {
}

// This reader is used as a stand-in for a reader that will actually export
// data. See [go.opentelemetry.io/otel/exporters] for exporters
// that can be used as or with readers.
// data. See https://pkg.go.dev/go.opentelemetry.io/otel/exporters for
// exporters that can be used as or with readers.
reader := metric.NewManualReader()

// Create a meter provider.
Expand All @@ -58,21 +57,20 @@ func Example() {
metric.WithReader(reader),
)

// Register as global meter provider so that it can
// that can used via [go.opentelemetry.io/otel.Meter]
// and accessed using [go.opentelemetry.io/otel.GetMeterProvider].
// Most instrumentation libraries use the global meter provider as default.
// If the global meter provider is not set then a no-op implementation
// is used and which fails to generate data.
otel.SetMeterProvider(meterProvider)

// Handle shutdown properly so that nothing leaks.
defer func() {
err := meterProvider.Shutdown(context.Background())
if err != nil {
log.Fatalln(err)
}
}()

// Register as global meter provider so that it can be used via otel.Meter
// and accessed using otel.GetMeterProvider.
// Most instrumentation libraries use the global meter provider as default.
// If the global meter provider is not set then a no-op implementation
// is used, which fails to generate data.
otel.SetMeterProvider(meterProvider)
}

func ExampleView() {
Expand Down

0 comments on commit 10b9f90

Please sign in to comment.