-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracing.go
35 lines (29 loc) · 870 Bytes
/
tracing.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
package main
import (
"context"
"go.opentelemetry.io/contrib/propagators/aws/xray"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/sdk/trace"
)
func setupTracing(ctx context.Context, res *resource.Resource) *trace.TracerProvider {
// communicate on localhost to the ADOT collector
// required to generate xray compatible IDs
t_exp, err := otlptracegrpc.New(ctx,
otlptracegrpc.WithInsecure(),
otlptracegrpc.WithEndpoint("0.0.0.0:4317"),
)
if err != nil {
panic(err)
}
tp := trace.NewTracerProvider(
trace.WithResource(res),
trace.WithBatcher(t_exp),
trace.WithSampler(trace.AlwaysSample()),
trace.WithIDGenerator(xray.NewIDGenerator()),
)
otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(xray.Propagator{})
return tp
}