Frameworks
Python
Celery

Celery

Celery is autoinstrumented!

Just add our code snippet to the top of your server’s entrypoint and you’re good to go.

Install the Python client

pip install iudex

Create a write-only API key 🔑

Click settings in the top left corner of the IUDEX dashboard and create a write-only API key.

Create a write-only API key

Add IUDEX into your app 🚀

Find the entrypoint for your app, e.g. tasks.py.

Add the highlighted code as shown below.

💡
  • import at the very top of the file, before all other imports
  • instrument(...) after imports but before any code, including app init
tasks.py
from iudex import instrument
# ^ Must run above all imports
from celery import Celery
from celery.signals import import worker_process_init
 
...
 
@worker_process_init.connect(weak=False)
def init_celery_tracing(*args, **kwargs):
    instrument(
        service_name="YOUR_SERVICE_NAME", # Highly encouraged
        iudex_api_key="WRITE_ONLY_IUDEX_KEY", # Only ever commit your WRITE ONLY key
        github_url="GITHUB_URL_TO_YOUR_REPO", # Optional, this sets up code linking
        env="prod", # Optional, dev, local, etc
    )
# ^ Must run before other code, including app setup
 
app = Celery("tasks", broker="amqp://localhost")
...

Set up Slack alerts 📣

Click the Slack logo in the top right of the dashboard and follow the prompts.

Slack integration button

Note: you must have admin permissions to add apps to your workspace.

Create a log 🪵

Add code to emit a log in your app. You can use print or Python’s logging module.

import logging
logger = logging.getLogger(__name__)
 
...
 
logger.info("Hello IUDEX!", extra={"iudex.slack_channel_id": "YOUR_SLACK_CHANNEL_ID"})

(In Slack, open the channel and click its name in the top left, then find its ID at the bottom of the dialog.)

Then simply run your celery app as usual to emit the log.

Verify 🧐

You should see the log in Slack and in your IUDEX dashboard log view.

Slack message

Log in IUDEX

Go in-depth 👉

Check out more in-depth guides on how to get the most out of IUDEX for your stack.