feat: tracer initialization and add OTLP text map propagator setup

This commit is contained in:
SoXX 2024-08-26 16:33:40 +02:00
parent 57dcb53aba
commit bef94becce
2 changed files with 13 additions and 2 deletions

View File

@ -17,6 +17,8 @@ import (
"google.golang.org/protobuf/types/known/timestamppb" "google.golang.org/protobuf/types/known/timestamppb"
) )
var tracer = otel.Tracer("git.anthrove.art/Anthrove/plug-sdk/v3/pkg/plug")
type Message struct { type Message struct {
Title string Title string
Body string Body string
@ -38,8 +40,6 @@ type Plug struct {
plugName string plugName string
} }
var tracer = otel.Tracer("git.anthrove.art/Anthrove/plug-sdk/v3/pkg/plug")
func NewPlug(ctx context.Context, plugName string, address string, port string, source models.Source) Plug { func NewPlug(ctx context.Context, plugName string, address string, port string, source models.Source) Plug {
return Plug{ return Plug{
ctx: ctx, ctx: ctx,

View File

@ -5,6 +5,7 @@ import (
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/trace" "go.opentelemetry.io/otel/sdk/trace"
) )
@ -15,6 +16,9 @@ func SetupTraceProvider(ctx context.Context, plugName string) error {
return err return err
} }
prop := newPropagator()
otel.SetTextMapPropagator(prop)
exporter, err := traceExporter(ctx) exporter, err := traceExporter(ctx)
if err != nil { if err != nil {
@ -39,3 +43,10 @@ func traceExporter(ctx context.Context) (trace.SpanExporter, error) {
return spanExporter, nil return spanExporter, nil
} }
func newPropagator() propagation.TextMapPropagator {
return propagation.NewCompositeTextMapPropagator(
propagation.TraceContext{},
propagation.Baggage{},
)
}