Connect Celery to Bugsink

When a Celery task fails, Bugsink shows you the exception, the application frame that raised it, and the name of the task the worker was running.

This guide covers the initial setup and Celery’s automatic capture of failed tasks. You’ll configure the SDK where your worker loads its Celery app, then queue a deliberate failure through a real worker to confirm it reaches Bugsink.

To follow along, create a Bugsink project and copy its DSN. The quickstart guide shows where to find it.

Install the SDK

Install the open-source Sentry SDK with its Celery support in the environment your worker uses. Bugsink accepts the Sentry event protocol, so the SDK can send task failures directly to your Bugsink project.

python -m pip install --upgrade "sentry-sdk[celery]"

Configure the Celery worker

Initialize the SDK in the module that creates your Celery app. The worker must import this module during startup, before it begins processing tasks:

import os

import sentry_sdk
from celery import Celery
from sentry_sdk.integrations.celery import CeleryIntegration

Read the DSN from the environment and enable the Celery integration before creating the app:

sentry_sdk.init(
    dsn=os.environ["SENTRY_DSN"],
    integrations=[CeleryIntegration()],
)

Set SENTRY_DSN in the environment where the worker runs. Use the DSN copied from your Bugsink project:

export SENTRY_DSN=https://key@bugsink.example/1

Queue a task that fails

A task does not need an SDK call. If it raises an exception and Celery marks the result as failed, the integration reports that exception from the worker. This inventory task raises ProductNotFound for an unknown product:

@app.task(name="inventory.reserve_product")
def reserve_product(sku, quantity=1):
    try:
        product = INVENTORY[sku]
    except KeyError:
        raise ProductNotFound(f"Product {sku} is not in inventory") from None

    if product["stock"] < quantity:
        raise ValueError(f"Only {product['stock']} units of {sku} are available")

    return {
        "sku": sku,
        "name": product["name"],
        "reserved": quantity,
    }

Start your worker in one terminal as usual:

celery -A inventory_worker.celery_app worker --loglevel=info

In another process, queue the task rather than calling its Python function directly:

from inventory_worker.tasks import reserve_product

result = reserve_product.delay("celery-missing")
print(result.get(timeout=30, propagate=False))

Celery records a FAILURE result and the worker logs the unhandled task exception.

See the failed task in Bugsink

Open your Bugsink project and select the new ProductNotFound issue. Its event points to the task body and uses inventory.reserve_product as the task and transaction name.

Bugsink preview

That’s it: failed Celery tasks will now be reported to Bugsink.

The integration runs inside the worker, so producers do not need to catch task errors or wait for results to report them. Each event includes the exception, the worker-side Python stack, the task name, and a celery_task_id tag that you can use to relate it to Celery’s result or logs.

Limitations

With the SDK’s default data settings, Celery task arguments and keyword arguments appear as [Filtered]. The task name, task ID, exception, and stack remain available without sending the values passed to the task.

For handled exceptions, logging, tags, structured context, and other SDK options, see the broader Python guide.