You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-07-17 01:12:45 +02:00
Add example for stdoutlog (#5242)
This commit is contained in:
@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
|
|
||||||
- Add `RecordFactory` in `go.opentelemetry.io/otel/log/logtest` to facilitate testing the bridge implementations. (#5263)
|
- Add `RecordFactory` in `go.opentelemetry.io/otel/log/logtest` to facilitate testing the bridge implementations. (#5263)
|
||||||
- Add `RecordFactory` in `go.opentelemetry.io/otel/sdk/log/logtest` to facilitate testing the exporter and processor implementations. (#5258)
|
- Add `RecordFactory` in `go.opentelemetry.io/otel/sdk/log/logtest` to facilitate testing the exporter and processor implementations. (#5258)
|
||||||
|
- Add example for `go.opentelemetry.io/otel/exporters/stdout/stdoutlog`. (#5242)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
32
exporters/stdout/stdoutlog/example_test.go
Normal file
32
exporters/stdout/stdoutlog/example_test.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// 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.
|
||||||
|
}
|
Reference in New Issue
Block a user