Skip to content

Commit 714fa75

Browse files
committed
docs(open-telemetry#5408): add example file
Signed-off-by: thomasgouveia <[email protected]>
1 parent cf66e2d commit 714fa75

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package otlplogfile_test
5+
6+
import (
7+
"context"
8+
"time"
9+
10+
"go.opentelemetry.io/otel/exporters/otlp/otlplog/otlplogfile"
11+
"go.opentelemetry.io/otel/log/global"
12+
"go.opentelemetry.io/otel/sdk/log"
13+
)
14+
15+
func Example() {
16+
ctx := context.Background()
17+
exp, err := otlplogfile.New(
18+
otlplogfile.WithPath("/tmp/otlp-logs.jsonl"),
19+
otlplogfile.WithFlushInterval(time.Second),
20+
)
21+
if err != nil {
22+
panic(err)
23+
}
24+
25+
processor := log.NewBatchProcessor(exp)
26+
provider := log.NewLoggerProvider(log.WithProcessor(processor))
27+
defer func() {
28+
if err := provider.Shutdown(ctx); err != nil {
29+
panic(err)
30+
}
31+
}()
32+
33+
global.SetLoggerProvider(provider)
34+
35+
// From here, the provider can be used by instrumentation to collect
36+
// telemetry.
37+
}

0 commit comments

Comments
 (0)