OpenTelemetry
Hatchet supports exporting traces from your tasks to an OpenTelemetry Collector to improve visibility into your Hatchet tasks.
Setup
Install the otel extra:
pip install hatchet-sdk[otel]Then create the instrumentor and call instrument():
from hatchet_sdk.opentelemetry.instrumentor import HatchetInstrumentor
HatchetInstrumentor().instrument()By default, HatchetInstrumentor creates a TracerProvider that sends spans to the Hatchet engine’s OTLP collector. You can also pass your own TracerProvider:
HatchetInstrumentor(
tracer_provider=your_tracer_provider,
).instrument()Options
| Option | Type | Default | Description |
|---|---|---|---|
tracer_provider | TracerProvider | — | Custom TracerProvider. If not set, one is created automatically. |
enable_hatchet_otel_collector | bool | True | Send traces to the Hatchet engine’s OTLP collector. |
schedule_delay_millis | int | — | Delay between consecutive exports of the BatchSpanProcessor. |
max_export_batch_size | int | — | Maximum batch size for the BatchSpanProcessor. |
max_queue_size | int | — | Maximum queue size for the BatchSpanProcessor. |
Spans
By default, Hatchet creates spans at the following points in the lifecycle of a task run:
- Producer spans — when a trigger is called on the client side (e.g.
run(),runNoWait(),push(),schedule()). - Consumer spans — when a worker handles a task run, such as starting to run the task (
hatchet.start_step_run) or cancelling a task (hatchet.cancel_step_run).
Span Names
| Span Name | Kind | Description |
|---|---|---|
hatchet.start_step_run | CONSUMER | Worker begins executing a task. |
hatchet.cancel_step_run | CONSUMER | Worker cancels a running task. |
hatchet.run_workflow | PRODUCER | Client triggers a workflow run. |
hatchet.run_workflows | PRODUCER | Client triggers multiple workflow runs. |
hatchet.schedule_workflow | PRODUCER | Client creates a scheduled workflow run. |
hatchet.push_event | PRODUCER | Client pushes an event. |
hatchet.bulk_push_event | PRODUCER | Client pushes events in bulk. |
hatchet.durable.wait_for | INTERNAL | Durable task waits for a signal/condition. |
Span Attributes
All spans include an instrumentor attribute set to "hatchet". Consumer spans (hatchet.start_step_run) include the following hatchet.* attributes:
| Attribute | Type | Description |
|---|---|---|
hatchet.tenant_id | string | The tenant ID for the task run. |
hatchet.worker_id | string | The worker handling the task. |
hatchet.workflow_run_id | string | The workflow run ID. |
hatchet.step_run_id | string | The task run ID. |
hatchet.step_id | string | The task ID. |
hatchet.workflow_name | string | The workflow name. |
hatchet.action_name | string | The action ID (format: workflowName:taskName). |
hatchet.step_name | string | The human-readable task name. |
hatchet.retry_count | int | Current retry attempt (0-indexed). |
hatchet.workflow_id | string | The workflow definition ID (if available). |
hatchet.workflow_version_id | string | The workflow version ID (if available). |
hatchet.parent_workflow_run_id | string | Parent workflow run ID (for child workflows). |
hatchet.child_workflow_index | int | Child workflow index (for child workflows). |
hatchet.child_workflow_key | string | Child workflow key (for child workflows). |
Producer spans (hatchet.run_workflow) include hatchet.step_name (the workflow being triggered) and, on success, hatchet.child_workflow_run_id.
Context Propagation
All SDKs:
- Automatically inject W3C
traceparentintoadditionalMetadataon producer spans, so consumer spans on the worker become children of the trigger span. - Provide an
HatchetAttributeSpanProcessorthat propagateshatchet.*attributes from the parent task run span to all child spans created within the task. This means any custom spans you create inside a task function will automatically carry the samehatchet.*attributes.