From 3dc5ff84abde321343db24b3fd20c21895bdebe4 Mon Sep 17 00:00:00 2001 From: Charith Ellawala Date: Tue, 28 Nov 2023 16:59:46 +0000 Subject: [PATCH] chore: Fix legacy OTLP exporter initialization (#1891) When the legacy OTLP exporter is configured with the `tracing` block, we need to create the exporter manually because the Otel library cannot read our custom environment implementation to read the endpoint and insecure configuration. Signed-off-by: Charith Ellawala Signed-off-by: Charith Ellawala --- internal/observability/tracing/tracing.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/observability/tracing/tracing.go b/internal/observability/tracing/tracing.go index 715ebf44b..baf615ff6 100644 --- a/internal/observability/tracing/tracing.go +++ b/internal/observability/tracing/tracing.go @@ -13,6 +13,7 @@ import ( "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" otelsdk "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/exporters/jaeger" //nolint:staticcheck + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" "go.opentelemetry.io/otel/semconv/v1.13.0/httpconv" "go.opentelemetry.io/otel/trace" "go.uber.org/zap" @@ -110,6 +111,11 @@ func configureOTLP(ctx context.Context) (func() error, error) { } } + exporter, err := otlptracegrpc.New(ctx, otlptracegrpc.WithEndpoint(conf.OTLP.CollectorEndpoint), otlptracegrpc.WithInsecure()) + if err != nil { + return nil, fmt.Errorf("failed to create OTLP exporter: %w", err) + } + envMap := map[string]string{ otel.ServiceNameEV.Name: *svcName, otel.TracesSamplerEV.Name: otel.ParentBasedTraceIDRatioSampler, @@ -128,7 +134,7 @@ func configureOTLP(ctx context.Context) (func() error, error) { return os.LookupEnv(key) } - return otel.InitTraces(ctx, otel.Env(env)) + return otel.InitTracesWithExporter(ctx, otel.Env(env), exporter) } func HTTPHandler(handler http.Handler, path string) http.Handler {