From bef94becce35c66056e14437fda4172dd11a17b1 Mon Sep 17 00:00:00 2001 From: SoXX Date: Mon, 26 Aug 2024 16:33:40 +0200 Subject: [PATCH] feat: tracer initialization and add OTLP text map propagator setup --- pkg/plug/server.go | 4 ++-- pkg/telemetry/tracing.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/plug/server.go b/pkg/plug/server.go index 33ef421..d410626 100644 --- a/pkg/plug/server.go +++ b/pkg/plug/server.go @@ -17,6 +17,8 @@ import ( "google.golang.org/protobuf/types/known/timestamppb" ) +var tracer = otel.Tracer("git.anthrove.art/Anthrove/plug-sdk/v3/pkg/plug") + type Message struct { Title string Body string @@ -38,8 +40,6 @@ type Plug struct { 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 { return Plug{ ctx: ctx, diff --git a/pkg/telemetry/tracing.go b/pkg/telemetry/tracing.go index 1679033..539458e 100644 --- a/pkg/telemetry/tracing.go +++ b/pkg/telemetry/tracing.go @@ -5,6 +5,7 @@ import ( "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" + "go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/sdk/trace" ) @@ -15,6 +16,9 @@ func SetupTraceProvider(ctx context.Context, plugName string) error { return err } + prop := newPropagator() + otel.SetTextMapPropagator(prop) + exporter, err := traceExporter(ctx) if err != nil { @@ -39,3 +43,10 @@ func traceExporter(ctx context.Context) (trace.SpanExporter, error) { return spanExporter, nil } + +func newPropagator() propagation.TextMapPropagator { + return propagation.NewCompositeTextMapPropagator( + propagation.TraceContext{}, + propagation.Baggage{}, + ) +}