We use cookies

We use cookies to ensure you get the best experience on our website. For more information on how we use cookies, please see our cookie policy.

By clicking "Accept", you agree to our use of cookies.
Learn more.

GuideOpenTelemetry

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

OptionTypeDefaultDescription
tracer_providerTracerProviderCustom TracerProvider. If not set, one is created automatically.
enable_hatchet_otel_collectorboolTrueSend traces to the Hatchet engine’s OTLP collector.
schedule_delay_millisintDelay between consecutive exports of the BatchSpanProcessor.
max_export_batch_sizeintMaximum batch size for the BatchSpanProcessor.
max_queue_sizeintMaximum queue size for the BatchSpanProcessor.

Spans

By default, Hatchet creates spans at the following points in the lifecycle of a task run:

  1. Producer spans — when a trigger is called on the client side (e.g. run(), runNoWait(), push(), schedule()).
  2. 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 NameKindDescription
hatchet.start_step_runCONSUMERWorker begins executing a task.
hatchet.cancel_step_runCONSUMERWorker cancels a running task.
hatchet.run_workflowPRODUCERClient triggers a workflow run.
hatchet.run_workflowsPRODUCERClient triggers multiple workflow runs.
hatchet.schedule_workflowPRODUCERClient creates a scheduled workflow run.
hatchet.push_eventPRODUCERClient pushes an event.
hatchet.bulk_push_eventPRODUCERClient pushes events in bulk.
hatchet.durable.wait_forINTERNALDurable 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:

AttributeTypeDescription
hatchet.tenant_idstringThe tenant ID for the task run.
hatchet.worker_idstringThe worker handling the task.
hatchet.workflow_run_idstringThe workflow run ID.
hatchet.step_run_idstringThe task run ID.
hatchet.step_idstringThe task ID.
hatchet.workflow_namestringThe workflow name.
hatchet.action_namestringThe action ID (format: workflowName:taskName).
hatchet.step_namestringThe human-readable task name.
hatchet.retry_countintCurrent retry attempt (0-indexed).
hatchet.workflow_idstringThe workflow definition ID (if available).
hatchet.workflow_version_idstringThe workflow version ID (if available).
hatchet.parent_workflow_run_idstringParent workflow run ID (for child workflows).
hatchet.child_workflow_indexintChild workflow index (for child workflows).
hatchet.child_workflow_keystringChild 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:

  1. Automatically inject W3C traceparent into additionalMetadata on producer spans, so consumer spans on the worker become children of the trigger span.
  2. Provide an HatchetAttributeSpanProcessor that propagates hatchet.* 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 same hatchet.* attributes.