From 37619eada96e44be156ffec47b3ff689889f234c Mon Sep 17 00:00:00 2001 From: Sam Xie Date: Thu, 25 Apr 2024 03:24:31 -0700 Subject: [PATCH] Add example for stdoutlog (#5242) --- CHANGELOG.md | 1 + exporters/stdout/stdoutlog/example_test.go | 32 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 exporters/stdout/stdoutlog/example_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d79b68ca82..8eba638ff43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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/sdk/log/logtest` to facilitate testing the exporter and processor implementations. (#5258) +- Add example for `go.opentelemetry.io/otel/exporters/stdout/stdoutlog`. (#5242) ### Changed diff --git a/exporters/stdout/stdoutlog/example_test.go b/exporters/stdout/stdoutlog/example_test.go new file mode 100644 index 00000000000..6498060337b --- /dev/null +++ b/exporters/stdout/stdoutlog/example_test.go @@ -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. +}