Skip to content

Commit

Permalink
fix(cloudotel): always install text map propagator
Browse files Browse the repository at this point in the history
Even if the trace exporting is not enabled, we should always extract and
propagate traces between services.
  • Loading branch information
odsod committed Oct 22, 2024
1 parent d2f1f6d commit 4c57ab0
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions cloudotel/traceexporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down

0 comments on commit 4c57ab0

Please sign in to comment.