-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
37 lines (29 loc) · 766 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"context"
"time"
"go.opentelemetry.io/contrib/bridges/otelslog"
"go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp"
"go.opentelemetry.io/otel/sdk/log"
)
func main() {
ctx := context.Background()
logExporter, err := otlploghttp.New(ctx, otlploghttp.WithInsecure())
if err != nil {
panic("failed to create exporter: " + err.Error())
}
logProvider := log.NewLoggerProvider(
log.WithProcessor(log.NewBatchProcessor(logExporter)),
)
defer logProvider.Shutdown(ctx)
logger := otelslog.NewLogger("log-sampler-demo", otelslog.WithLoggerProvider(logProvider))
counter := 0
for {
counter++
logger.Info("Counter incremented",
"value", counter,
"timestamp", time.Now(),
)
time.Sleep(1 * time.Second)
}
}