Python | Durable Task SDK
This sample demonstrates OpenTelemetry distributed tracing with the Durable Task SDK for Python. The SDK automatically creates activity spans with durabletask.* tags and propagates W3C trace context from orchestrations to activities — no manual span creation needed in your activity code.
-
Start the infrastructure (emulator + Jaeger):
docker compose up -d
-
Install dependencies and start the worker:
python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate pip install -r requirements.txt python worker.py
-
In a new terminal, run the client:
source venv/bin/activate python client.py -
View traces:
- Jaeger UI: http://localhost:16686 (search for service
DistributedTracingSample) - DTS Dashboard: http://localhost:8082
- Jaeger UI: http://localhost:16686 (search for service
Open the Jaeger UI, select the DistributedTracingSample service, and click Find Traces. You'll see a single trace with 5 Spans — the parent create_orchestration:OrderProcessingOrchestration with 4 child activity spans:
Click on the trace to see the full span tree with parent-child hierarchy and rich durabletask.* tags (automatically added by the SDK):
The Durable Task Python SDK has built-in OpenTelemetry support:
- Client side: When you schedule an orchestration with an active OpenTelemetry span, the SDK captures the W3C trace context (
traceparent/tracestate) and sends it with the request. - Orchestrator side: The SDK stores the parent trace context and passes it to all child activities and sub-orchestrations.
- Activity side: The SDK wraps each activity execution in an
activity:<name>span as a child of the orchestration's trace context, withdurabletask.task.instance_id,durabletask.task.name, anddurabletask.task.task_idtags.
All you need is to configure a TracerProvider with an exporter — the SDK does the rest.
The Jaeger UI shows a single trace for the entire orchestration with nested child spans for each activity. This helps you:
- Identify slow activities within an orchestration
- See the sequential flow of function chaining
- Correlate the full orchestration lifecycle in one trace
- Debug failures with full context
docker compose down
