The Go client provides distributed tracing support through OpenTracing. Tracing can be configured by providing an opentracing.Tracer implementation in ClientOptions and WorkerOptions during client and worker instantiation, respectively. Tracing allows you to view the call graph of a workflow along with its activities, child workflows etc. For more details on how to configure and leverage tracing, see the OpenTracing documentation. The OpenTracing support has been validated using Jaeger, but other implementations mentioned here should also work. Tracing support utilizes generic context propagation support provided by the client.
We provide a standard way to propagate custom context across a workflow.
ClientOptions and WorkerOptions
allow configuring a context propagator. The context propagator extracts and passes on information present in the
workflow.Context objects across the workflow. Once a context propagator is configured, you should be able to access the required values
in the context objects as you would normally do in Go.
For a sample, the Go client implements a tracing context propagator.
Server-Side Headers Support
On the server side, Temporal provides a mechanism to propagate what it calls headers across different workflow transitions.
The client leverages this to pass around selected context information. HeaderReader
and HeaderWriter are interfaces
that allow reading and writing to the Temporal server headers. The client already provides implementations
HeaderWriter sets a field in the header. Headers is a map, so setting a value for the the same key
multiple times will overwrite the previous values.
HeaderReader iterates through the headers map and runs the
provided handler function on each key/value pair, allowing you to deal with the fields you are interested in.
Context propagators require implementing the following four methods to propagate selected context across a workflow:
Injectis meant to pick out the context keys of interest from a Go context.Context object and write that into the headers using the HeaderWriter interface
InjectFromWorkflowis the same as above, but operates on a workflow.Context object
Extractreads the headers and places the information of interest back into the context.Context object
ExtractToWorkflowis the same as above, but operates on a workflow.Context object
The tracing context propagator shows a sample implementation of context propagation.
Q & A
Is there a complete example?
The context propagation sample configures a custom context propagator and shows context propagation of custom keys across a workflow and an activity.
Can I configure multiple context propagators?
Yes, we recommended that you configure multiple context propagators with each propagator meant to propagate a particular type of context.