Skip to main content

opentelemetry-instrumentation-absurd

Tests PyPI Python versions License: MIT

OpenTelemetry instrumentation for the Absurd durable-task SDK (absurd-sdk).

Absurd (absurd_sdk.AsyncAbsurd) is a Postgres-backed durable task queue: a producer spawn()s a task and a worker work_batch() claims and runs the registered handler, possibly in a different process. Without instrumentation the two halves live in separate traces, so a task's execution cannot be linked back to whatever spawned it.

This instrumentor follows the standard producer/consumer span shape for a task queue:

  • AsyncAbsurd.spawn() is wrapped to open a CLIENT span named after the task and inject the current trace context into the task's headers. Absurd persists headers on the task row and hands them back to the handler via ctx.headers.
  • AsyncAbsurd.register_task() is wrapped so every registered handler runs inside a running:<task> SERVER span whose parent is extracted from those headers.

The two spans share one trace, so a task's execution is linked back to whatever spawned it — even when the spawner and the worker run in different processes.

trigger (your span)
└── report                 CLIENT   ← spawn()  (process A)
    └── running:report     SERVER   ← handler  (process B)

Installation

pip install opentelemetry-instrumentation-absurd
# or
uv add opentelemetry-instrumentation-absurd

Usage

Install the instrumentor once per process, on both the spawn side and the worker side:

from opentelemetry.instrumentation.absurd import AbsurdInstrumentor

AbsurdInstrumentor().instrument()

That is all — no changes to your spawn() calls or task handlers are required. Only AsyncAbsurd is instrumented.

You can pass an explicit TracerProvider:

AbsurdInstrumentor().instrument(tracer_provider=my_tracer_provider)

Because this package ships an opentelemetry_instrumentor entry point, it is also picked up automatically by opentelemetry-instrument:

opentelemetry-instrument python your_app.py

Producer / consumer example

import asyncio

from absurd_sdk import AsyncAbsurd
from opentelemetry.instrumentation.absurd import AbsurdInstrumentor

AbsurdInstrumentor().instrument()

app = AsyncAbsurd('postgresql://localhost/absurd', queue_name='workflows')


@app.register_task(name='report')
async def report(params, ctx):
    # Runs inside a `running:report` SERVER span parented to the spawner.
    return {'value': params['value'] * 2}


async def main() -> None:
    # Opens a `report` CLIENT span and injects the trace context into the task headers.
    await app.spawn('report', {'value': 7}, queue='workflows')


asyncio.run(main())

Span attributes

Both spans carry these attributes (set when available):

Attribute Span Description
absurd.task.name CLIENT + SERVER The registered task name.
absurd.queue CLIENT + SERVER The queue the task was spawned on.
absurd.task.id CLIENT + SERVER The task UUID (stringified).
absurd.run.id CLIENT The run UUID assigned by spawn().
absurd.task.attempt SERVER The current attempt number of the run.
absurd.task.idempotency_key CLIENT Set only when an idempotency key is given.

The trace context is propagated through the task headers under the otel.absurd.context key using the globally configured OpenTelemetry propagator (W3C traceparent by default), so any caller headers you pass are preserved.

How it works

spawn() and the registered handler are wrapped with wrapt. On spawn() the current context is injected into a fresh carrier nested under a single header key; the worker extracts that carrier and parents its SERVER span to the spawner's CLIENT span. If a task was spawned before instrumentation (no carrier present), the handler still runs in its own SERVER span — it just starts a new trace.

Compatibility

  • Python 3.10+
  • absurd-sdk >= 0.4.0
  • opentelemetry-api >= 1.0

Development

make install   # uv sync --all-groups
make test      # uv run pytest
make check     # ruff check + ruff format --check

AI disclaimer

This code was written with the help of AI.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opentelemetry_instrumentation_absurd-0.1.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file opentelemetry_instrumentation_absurd-0.1.0.tar.gz.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_absurd-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6c5086707b0c24e1d53c562134504db8fbe8454476ca4ecfb27fe2829a644d3f
MD5 8a3bab14083e0a08c89787159345a959
BLAKE2b-256 743484b4ccdb2d00a905b044e4a6acaf25efbd40de314c8b8047a7757979d1b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for opentelemetry_instrumentation_absurd-0.1.0.tar.gz:

Publisher: release.yml on jirikuncar/opentelemetry-instrumentation-absurd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opentelemetry_instrumentation_absurd-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_absurd-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8df44d213a3e8248a3e7b7ac192936bd43516ddf43d5a0fc4a85b78153652ece
MD5 8e8030ff575aae5296a2447c75d9bb60
BLAKE2b-256 9ec7ffd1454d1bd1899061531096c159c9f0509bafcedd78104772de00505d0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for opentelemetry_instrumentation_absurd-0.1.0-py3-none-any.whl:

Publisher: release.yml on jirikuncar/opentelemetry-instrumentation-absurd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page