Skip to content

Commit

Permalink
Add example test for otlploggrpc (open-telemetry#5615)
Browse files Browse the repository at this point in the history
  • Loading branch information
XSAM authored Jul 12, 2024
1 parent 19a131b commit aebcbfc
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions exporters/otlp/otlplog/otlploggrpc/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package otlploggrpc_test

import (
"context"

"go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc"
"go.opentelemetry.io/otel/log/global"
"go.opentelemetry.io/otel/sdk/log"
)

func Example() {
ctx := context.Background()
exp, err := otlploggrpc.New(ctx)
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 aebcbfc

Please sign in to comment.