1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-07 23:02:15 +02:00
opentelemetry-go/exporters/stdout/stdoutlog/example_test.go
2024-04-25 12:24:31 +02:00

33 lines
674 B
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package stdoutlog_test
import (
"context"
"go.opentelemetry.io/otel/exporters/stdout/stdoutlog"
"go.opentelemetry.io/otel/log/global"
"go.opentelemetry.io/otel/sdk/log"
)
func Example() {
exp, err := stdoutlog.New()
if err != nil {
panic(err)
}
processor := log.NewSimpleProcessor(exp)
provider := log.NewLoggerProvider(log.WithProcessor(processor))
defer func() {
if err := provider.Shutdown(context.Background()); err != nil {
panic(err)
}
}()
global.SetLoggerProvider(provider)
// From here, the provider can be used by instrumentation to collect
// telemetry.
}