Celery Instrumentation

AppSignal for PythonThis feature requires version 0.1.0 or higher.
CeleryThis feature requires version 4.0 or higher.

Celery is a simple, flexible, and reliable distributed system to process vast amounts of messages, while providing operations with the tools required to maintain such a system.

Installation

Don't forget to install the AppSignal for Python package in your application first.

First, install the opentelemetry-instrumentation-celery package. We also recommend installing the Redis instrumentation package. To add both instrumentation packages to your project, add the following lines to your requirements.txt file:

shell
# requirements.txt opentelemetry-instrumentation-celery opentelemetry-instrumentation-redis

The AppSignal for Python integration will automatically use this instrumentation when the corresponding package is installed. To disable this instrumentation without uninstalling the package, use the disable_default_instrumentations configuration option.

Setup

Celery requires some extra setup, as it's an application component that's started separately.

As shown in the example below, the appsignal module needs to be imported in the main file used to start Celery, and the appsignal.start() method needs to be called from a method with the @worker_process_init.connect decorator.

In the example below, this initialization takes place in the tasks.py file. This file may be named differently in your application.

python
# tasks.py # Import this file import appsignal from celery import Celery # Import this file from celery.signals import worker_process_init # Add the init_celery_tracing method with its annotation @worker_process_init.connect(weak=False) def init_celery_tracing(*args, **kwargs): appsignal.start() app = Celery('tasks', broker='redis://localhost') @app.task def slow_task(): # Do things