From 4c57ab0434f868f838bc945334760b4dec704d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20S=C3=B6derlund?= Date: Tue, 22 Oct 2024 11:24:03 +0200 Subject: [PATCH] fix(cloudotel): always install text map propagator Even if the trace exporting is not enabled, we should always extract and propagate traces between services. --- cloudotel/traceexporter.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cloudotel/traceexporter.go b/cloudotel/traceexporter.go index c2802267..df94446f 100644 --- a/cloudotel/traceexporter.go +++ b/cloudotel/traceexporter.go @@ -28,6 +28,12 @@ func StartTraceExporter( exporterConfig TraceExporterConfig, resource *resource.Resource, ) (func(context.Context) error, error) { + // configure open telemetry to read trace context from GCP `x-cloud-trace-context` header. + otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator( + gcppropagator.CloudTraceFormatPropagator{}, + propagation.TraceContext{}, + propagation.Baggage{}, + )) if !exporterConfig.Enabled { return func(context.Context) error { return nil }, nil } @@ -48,14 +54,7 @@ func StartTraceExporter( sdktrace.WithSampler(sdktrace.ParentBased(sdktrace.TraceIDRatioBased(exporterConfig.SampleProbability))), ) otel.SetTracerProvider(tracerProvider) - // configure open telemetry to read trace context from GCP `x-cloud-trace-context` header. - otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator( - gcppropagator.CloudTraceFormatPropagator{}, - propagation.TraceContext{}, - propagation.Baggage{}, - )) opencensus.InstallTraceBridge() - cleanup := func(ctx context.Context) error { if err := tracerProvider.ForceFlush(ctx); err != nil { return fmt.Errorf("error shutting down trace exporter: %v", err)