diff --git a/go.mod b/go.mod index 9a040d6..1b38166 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/onsi/gomega v1.27.10 github.com/prometheus/client_golang v1.16.0 github.com/stretchr/testify v1.8.4 + go.opentelemetry.io/contrib/propagators/autoprop v0.49.0 go.opentelemetry.io/otel v1.24.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 @@ -34,6 +35,10 @@ require ( github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect github.com/joho/godotenv v1.5.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + go.opentelemetry.io/contrib/propagators/aws v1.24.0 // indirect + go.opentelemetry.io/contrib/propagators/b3 v1.24.0 // indirect + go.opentelemetry.io/contrib/propagators/jaeger v1.24.0 // indirect + go.opentelemetry.io/contrib/propagators/ot v1.24.0 // indirect go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/proto/otlp v1.1.0 // indirect golang.org/x/tools v0.16.1 // indirect diff --git a/go.sum b/go.sum index fa2c8f4..c85642b 100644 --- a/go.sum +++ b/go.sum @@ -156,6 +156,16 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.opentelemetry.io/contrib/propagators/autoprop v0.49.0 h1:Jbr/9/jv1QpINge/fvJD4kUkW9/TqRNWU7H2GSK/Vb8= +go.opentelemetry.io/contrib/propagators/autoprop v0.49.0/go.mod h1:aZTdrjEnMOr6ODgjCQ955njFMLRDo1IJdTNS+agSPjA= +go.opentelemetry.io/contrib/propagators/aws v1.24.0 h1:cuwQmy9nGJi99fbwUfZSygCL3d347ddnSCWRuiVjhJ8= +go.opentelemetry.io/contrib/propagators/aws v1.24.0/go.mod h1:7HbFx8Hiiuce72QONjbOtU+3QU+Scs9VOHZIrdmi1rw= +go.opentelemetry.io/contrib/propagators/b3 v1.24.0 h1:n4xwCdTx3pZqZs2CjS/CUZAs03y3dZcGhC/FepKtEUY= +go.opentelemetry.io/contrib/propagators/b3 v1.24.0/go.mod h1:k5wRxKRU2uXx2F8uNJ4TaonuEO/V7/5xoz7kdsDACT8= +go.opentelemetry.io/contrib/propagators/jaeger v1.24.0 h1:CKtIfwSgDvJmaWsZROcHzONZgmQdMYn9mVYWypOWT5o= +go.opentelemetry.io/contrib/propagators/jaeger v1.24.0/go.mod h1:Q5JA/Cfdy/ta+5VeEhrMJRWGyS6UNRwFbl+yS3W1h5I= +go.opentelemetry.io/contrib/propagators/ot v1.24.0 h1:6lf4HoYefKDOTUSCatwkpzliUYihAvlN0omfpOn5IDs= +go.opentelemetry.io/contrib/propagators/ot v1.24.0/go.mod h1:A406hNQ7A0EWsOFzWI1p53YaYQXe12C9f6wGHUxfh0g= go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 h1:t6wl9SPayj+c7lEIFgm4ooDBZVb01IhLB4InpomhRw8= diff --git a/internal/tracing/tracing.go b/internal/tracing/tracing.go index d1adafb..7a6d8eb 100644 --- a/internal/tracing/tracing.go +++ b/internal/tracing/tracing.go @@ -16,6 +16,8 @@ import ( tracesdk "go.opentelemetry.io/otel/sdk/trace" semconv "go.opentelemetry.io/otel/semconv/v1.4.0" "go.opentelemetry.io/otel/trace" + "go.opentelemetry.io/contrib/propagators/autoprop" + ) const ( @@ -33,38 +35,42 @@ func init() { cerberusTracer = otel.Tracer(CerberusTracerName) } -func SetTracingProvider(provider string, samplingRation float64, timeout float64) (err error) { - var exporter *otlptrace.Exporter - - switch provider { - case HTTPTracingProvider: - exporter, err = otlptracehttp.New(context.Background(), - otlptracehttp.WithTimeout(time.Second*time.Duration(timeout)), - ) - case GRPCTracingProvider: - exporter, err = otlptracegrpc.New(context.Background(), - otlptracegrpc.WithTimeout(time.Second*time.Duration(timeout)), - ) - default: - err = fmt.Errorf("invalid-tracing-provider") - } - - if err != nil { - return err - } - - tp = tracesdk.NewTracerProvider( - tracesdk.WithBatcher(exporter), - tracesdk.WithSampler(tracesdk.ParentBased(tracesdk.TraceIDRatioBased(samplingRation))), - tracesdk.WithResource(resource.NewWithAttributes( - semconv.SchemaURL, - semconv.ServiceNameKey.String(ServiceName), - )), - ) - cerberusTracer = tp.Tracer(CerberusTracerName) - return +func SetTracingProvider(provider string, samplingRatio float64, timeout float64) (err error) { + var exporter *otlptrace.Exporter + + switch provider { + case HTTPTracingProvider: + exporter, err = otlptracehttp.New(context.Background(), + otlptracehttp.WithTimeout(time.Second*time.Duration(timeout)), + ) + case GRPCTracingProvider: + exporter, err = otlptracegrpc.New(context.Background(), + otlptracegrpc.WithTimeout(time.Second*time.Duration(timeout)), + ) + default: + err = fmt.Errorf("invalid-tracing-provider") + } + + if err != nil { + return err + } + + tp = tracesdk.NewTracerProvider( + tracesdk.WithBatcher(exporter), + tracesdk.WithSampler(tracesdk.ParentBased(tracesdk.TraceIDRatioBased(samplingRatio))), + tracesdk.WithResource(resource.NewWithAttributes( + semconv.SchemaURL, + semconv.ServiceNameKey.String(ServiceName), + )), + ) + cerberusTracer = tp.Tracer(CerberusTracerName) + + otel.SetTextMapPropagator(autoprop.NewTextMapPropagator()) + + return nil } + func StartSpan(ctx context.Context, spanName string, extraAttrs ...attribute.KeyValue) (context.Context, trace.Span) { newCtx, span := cerberusTracer.Start(ctx, spanName, trace.WithSpanKind(trace.SpanKindServer),