Temporal (tracing)
Temporal (tracing)
Temporal is a durable execution platform for long-running applications. Respan instruments the Temporal Python SDK through Temporal’s official replay-aware OpenTelemetry interceptor, preserving Temporal context propagation and replay behavior while emitting canonical Respan workflow and task spans.
Set up Respan
Create an account at platform.respan.ai and grab an API key.
Run npx @respan/cli setup to set up with your coding agent.
Setup
Set environment variables
Set RESPAN_BASE_URL only when exporting to a custom Respan endpoint. The Temporal client address is configured separately when you call Client.connect().
Initialize and run
Initialize Respan before connecting the Temporal client. TemporalInstrumentor automatically appends its interceptor to Client.connect(), and workers created from that client inherit the interceptor.
Run a Temporal development server or point Client.connect() at your Temporal deployment before starting this example.
View your trace
Open the Traces page to see the workflow lifecycle, activity execution, and Temporal client operations in one trace tree.
How automatic injection works
Passing TemporalInstrumentor() to Respan activates a patch on temporalio.client.Client.connect. Every client connected after initialization receives instrumentor.interceptor; workers created with that client use the same interceptor and preserve trace context across Temporal boundaries.
If the interceptors argument already contains a Temporal TracingInterceptor, Respan does not append a second tracing interceptor. This prevents duplicate spans.
Initialize Respan before the first Client.connect() call. Clients created before activation are not retrofitted.
Explicit interceptor wiring
Temporal test environments and custom client factories expose an explicit interceptors list. Use the same interceptor instance through instrumentor.interceptor:
The Temporal example suite uses this wiring with Temporal’s official time-skipping test server, so it does not require an external Temporal cluster. The first run downloads the official test-server binary.
Captured operations
The instrumentor adapts the operations emitted by Temporal’s official Python tracing interceptor.
Operation names include the workflow, activity, signal, query, or update type when Temporal exposes it. Workflow lifecycle operations are classified as Respan workflow spans; the other Temporal operations are classified as task spans.
Workflow-side spans follow Temporal’s replay safeguards. By default, the official interceptor creates them only when an overarching client span is present. See always_create_workflow_spans below if workflows are started from schedules, the CLI, or another source without that parent context.
Configuration
TemporalInstrumentor options
Respan options
Content controls
Content capture is enabled by default. It can include operation arguments and fields such as workflow or activity type, workflow ID, update ID, and task queue when Temporal exposes those values to the interceptor. Temporal headers and RPC metadata are never captured.
Disable content capture when arguments or identifiers can contain sensitive data:
With content capture disabled, spans retain the stable operation and workflow/activity type needed to inspect the trace, but omit arguments and Temporal IDs. Error details are reduced to the exception class rather than the exception message.
Errors and lifecycle
Successful Temporal operations receive backend-visible success status. Failed operations receive OpenTelemetry error status together with status_code and error.message, and their canonical output records an error result. When capture_content=False, the error message contains only the exception class.
activate() and deactivate() are idempotent and safe across multiple instrumentor instances. The Client.connect() patch remains active until the last active Temporal instrumentor is deactivated. Existing clients retain the interceptor they received at connection time.
When Respan owns the instrumentor lifecycle, call respan.shutdown() during application shutdown to flush pending telemetry and deactivate instrumentation: