OpenTelemetry
OpenTelemetry support is currently only available for the Python SDK.
Hatchet supports exporting traces from your tasks to an OpenTelemetry Collector to improve visibility into your Hatchet tasks.
Usage
Setup
Hatchet’s SDK provides an instrumentor that auto-instruments Hatchet code if you opt in. Setup is straightforward:
First, install the otel
extra with (e.g.) pip install hatchet-sdk[otel]
. Then, import the instrumentor:
from path.to.your.trace.provider import trace_provider
from hatchet_sdk.opentelemetry.instrumentor import HatchetInstrumentor
HatchetInstrumentor(tracer_provider=trace_provider).instrument()
You bring your own trace provider and plug it into the HatchetInstrumentor
, call instrument
, and that’s it!
Check out the OpenTelemetry documentation for more information on how to set up a trace provider.
Spans
By default, Hatchet creates spans at the following points in the lifecycle of a task run:
- When a trigger is run on the client side, e.g.
run()
orpush()
is called. - When a worker handles a task event, such as starting to run the task or cancelling the task
In addition, you’ll get a handful of attributes set (prefixed by hatchet.
) on the task run events, such as the task name and the worker ID, as well as success/failure states, and so on.
Some other important notes:
- The instrumentor will automatically propagate the trace context between task runs, so if you spawn a task from another task, the child will correctly show up as a child of its parent in the trace waterfall.
- You can exclude specific attributes from being attached to spans by providing the
otel
configuration option on theClientConfig
and passing a list ofexcluded_attributes
, which come from this list.