File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
exporters/otlp/otlplog/otlplogfile Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments