plug-sdk/pkg/telemetry/tracing.go
SoXX 0ab2d12c39 feat(telemetry): added base functions
added base function for OTEL Setup
2024-08-26 13:00:51 +02:00

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
}