cloud run opentelemetry go

getting distributed traces to connect

SEAN K.H. LIAO

cloud run opentelemetry go

getting distributed traces to connect

cloud run

Google Cloud Run takes your container and runs it serverlessly on a managed platform. It also means you get quite a bit of observability built in for "free", with load balancer logs, metrics, and traces available to query. Now with distributed tracing, you can connect your traces to it.

cloud trace

Cloud Trace has its own propagationheader and format: x-cloud-trace-context: trace-id/span-id/o=options. It's what the load balancers are documented to set.

In Go, using opentelemetry, that means you need a TextMapPropagator to parse the header and save it as a span context in your context.Context. Thankfully, they've provided one at CloudTraceFormatPropagator.

What they don't document yet is that the load balancers now also set the standard traceparent header, So the above is all unnecessary, the standard TraceContext propagator is all that's needed.

http2

Cloud Run has the option to do http2 end to end. For Go, this means using h2c to wrap your handlers and allow it to handle the upgrade. Important to note here is that h2c doesn't propagate the context properly, so if your h2c handler isn't the outermost one, the propagators will extract a trace id, set it in a context, only for it to be abandoned by h2c, and your calls to tracer.Start will start new traces not connected to anything.