forked from open-telemetry/opentelemetry-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(open-telemetry#5408): add example file
Signed-off-by: thomasgouveia <[email protected]>
- Loading branch information
1 parent
1869179
commit eb79f04
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} |