42 lines
720 B
Go
42 lines
720 B
Go
package telemetry
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.opentelemetry.io/otel"
|
|
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
|
|
"go.opentelemetry.io/otel/sdk/trace"
|
|
)
|
|
|
|
func SetupTraceProvider(ctx context.Context, plugName string) error {
|
|
res, err := newResource(plugName)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
exporter, err := traceExporter(ctx)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
provider := trace.NewTracerProvider(
|
|
trace.WithResource(res),
|
|
trace.WithBatcher(exporter),
|
|
)
|
|
|
|
otel.SetTracerProvider(provider)
|
|
return nil
|
|
}
|
|
|
|
func traceExporter(ctx context.Context) (trace.SpanExporter, error) {
|
|
spanExporter, err := otlptracegrpc.New(ctx)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return spanExporter, nil
|
|
}
|