Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk/metric: Update package example #4540

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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