diff --git a/exporters/otlp/otlplog/otlplogfile/example_test.go b/exporters/otlp/otlplog/otlplogfile/example_test.go new file mode 100644 index 000000000000..a46b9fc1e2ad --- /dev/null +++ b/exporters/otlp/otlplog/otlplogfile/example_test.go @@ -0,0 +1,37 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package otlplogfile_test + +import ( + "context" + "time" + + "go.opentelemetry.io/otel/exporters/otlp/otlplog/otlplogfile" + "go.opentelemetry.io/otel/log/global" + "go.opentelemetry.io/otel/sdk/log" +) + +func Example() { + ctx := context.Background() + exp, err := otlplogfile.New( + otlplogfile.WithPath("/tmp/otlp-logs.jsonl"), + otlplogfile.WithFlushInterval(time.Second), + ) + if err != nil { + panic(err) + } + + processor := log.NewBatchProcessor(exp) + provider := log.NewLoggerProvider(log.WithProcessor(processor)) + defer func() { + if err := provider.Shutdown(ctx); err != nil { + panic(err) + } + }() + + global.SetLoggerProvider(provider) + + // From here, the provider can be used by instrumentation to collect + // telemetry. +}