Skip to content

Commit

Permalink
docs(open-telemetry#5408): add example file
Browse files Browse the repository at this point in the history
Signed-off-by: thomasgouveia <[email protected]>
  • Loading branch information
thomasgouveia committed Aug 27, 2024
1 parent 1869179 commit eb79f04
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions exporters/otlp/otlplog/otlplogfile/example_test.go
Original file line number Diff line number Diff line change
@@ -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.
}

0 comments on commit eb79f04

Please sign in to comment.