TracerProvider.
Python
Installation
The OTel integration is an optional extra. Install it alongside the core SDK:The
[otel] extra is required. Importing HatchetInstrumentor without it raises ModuleNotFoundError with a message explaining which packages are missing.Basic setup
CallHatchetInstrumentor().instrument() before creating the Hatchet client and registering any tasks. The instrumentor patches internal SDK methods automatically — no changes to your task functions are needed.
worker.py
HatchetInstrumentor creates an SDK TracerProvider, registers a BatchSpanProcessor that exports to the Hatchet engine’s OTLP endpoint (using the same connection settings as the client), and sets the provider as the global OTel provider.
Sending traces to an external collector
Pass your ownTracerProvider to forward spans to an additional destination. Traces will be sent to both Hatchet and your external collector:
worker.py
HatchetInstrumentor parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
tracer_provider | TracerProvider | None | Custom provider. If omitted, an SDK provider is created or the existing global one is reused. |
meter_provider | MeterProvider | None | Custom meter provider. Defaults to a no-op provider. |
config | ClientConfig | None | Client configuration used to derive the Hatchet OTLP endpoint and token. |
enable_hatchet_otel_collector | bool | True | Whether to export spans to the Hatchet engine’s built-in OTLP collector. |
schedule_delay_millis | int | OTel default | Delay between exports in the BatchSpanProcessor. |
max_export_batch_size | int | OTel default | Maximum batch size for the BatchSpanProcessor. |
max_queue_size | int | OTel default | Maximum queue size for the BatchSpanProcessor. |
Custom child spans
Once instrumented, you can add child spans inside your task functions using the standard OTel API. These spans automatically inherit the Hatchet task span as their parent.worker.py
Propagating trace context through triggers
When you trigger a workflow from instrumented code, theHatchetInstrumentor automatically injects the W3C traceparent header into the run’s additional_metadata. The worker-side instrumentor extracts it and makes the step run span a child of the triggering span.
trigger.py
Go
Installation
Import theopentelemetry sub-package from the Hatchet Go SDK:
Basic setup
Create anInstrumentor and register its middleware on the worker:
worker.go
HATCHET_CLIENT_HOST_PORT, HATCHET_CLIENT_TOKEN, HATCHET_CLIENT_TLS_STRATEGY).
Options
| Option | Description |
|---|---|
WithTracerProvider(tp) | Use a custom SDK TracerProvider. |
DisableHatchetCollector() | Do not forward spans to the Hatchet engine. |
WithBatchSpanProcessorOptions(opts...) | Configure the BatchSpanProcessor used for the Hatchet exporter. |
What gets traced
The instrumentor wraps the following operations in OTel spans:| Operation | Span name | Kind |
|---|---|---|
| Task run start | hatchet.start_step_run | CONSUMER |
| Task run cancel | hatchet.cancel_step_run | CONSUMER |
| Trigger a workflow | hatchet.run_workflow | PRODUCER |
| Trigger multiple workflows | hatchet.run_workflows | PRODUCER |
| Schedule a workflow | hatchet.schedule_workflow | PRODUCER |
| Push an event | hatchet.push_event | PRODUCER |
| Bulk push events | hatchet.bulk_push_event | PRODUCER |
| Durable wait | hatchet.durable.wait_for | INTERNAL |
hatchet.* attributes so you can filter by task, workflow, worker, or tenant in your tracing backend:
| Attribute | Description |
|---|---|
hatchet.workflow_name | Name of the workflow |
hatchet.step_run_id | ID of the specific task run |
hatchet.workflow_run_id | ID of the parent workflow run |
hatchet.worker_id | ID of the worker that handled the task |
hatchet.tenant_id | Tenant the run belongs to |
hatchet.retry_count | Number of retries at the time of execution |
hatchet.payload | Input payload (Python: may be excluded via excluded_attributes) |
The
HatchetAttributeSpanProcessor (both Python and Go) injects hatchet.* attributes into every child span created within a task run context, so spans you create with get_tracer(__name__) are also queryable by task ID.OTel attributes reference (Python)
TheOTelAttribute enum in hatchet_sdk.utils.opentelemetry lists all attribute keys. You can pass values from this enum to exclude specific attributes from spans via the excluded_attributes config option.
OTelAttribute member | Span attribute key | Description |
|---|---|---|
WORKFLOW_NAME | hatchet.workflow_name | Workflow name |
STEP_RUN_ID | hatchet.step_run_id | Task run ID |
WORKFLOW_RUN_ID | hatchet.workflow_run_id | Workflow run ID |
WORKER_ID | hatchet.worker_id | Worker ID |
TENANT_ID | hatchet.tenant_id | Tenant ID |
RETRY_COUNT | hatchet.retry_count | Retry count |
ACTION_PAYLOAD | hatchet.payload | Input payload |
EVENT_KEY | hatchet.event_key | Event key (push_event spans) |
SIGNAL_KEY | hatchet.signal_key | Signal key (durable wait spans) |
Next steps
Dashboard
View traces collected by the Hatchet engine in the dashboard.
Task logs
Correlate OTel traces with task log output.