Python agent and Celery

If you are using Celery as a distributed task queuing system, you can use the Python agent to record Celery processes as non-web transactions.

To get the Python agent working with Celery, first follow the agent installation instructions to install, configure, and test the agent. Then use these Celery-specific instructions.

Run Celery

The command you use to run Celery with the agent depends on your Celery version and your specific setup.


If you use the celery command, include any custom options:

NEW_RELIC_CONFIG_FILE=/some/path/newrelic.ini newrelic-admin run-program celery YOUR_COMMAND_OPTIONS

For example:

NEW_RELIC_CONFIG_FILE=/some/path/newrelic.ini newrelic-admin run-program celery -A tasks worker --loglevel=info

The celeryd run command is deprecated in newer Celery releases. If you still use celeryd, include any custom options:

NEW_RELIC_CONFIG_FILE=some/path/newrelic.ini newrelic-admin run-program celeryd YOUR_COMMAND_OPTIONS

If you start Celery with a Django management command, use Replace the celery command with your Django command, and include any custom options:

NEW_RELIC_CONFIG_FILE=/some/path/newrelic.ini newrelic-admin run-program python celery YOUR_COMMAND_OPTIONS
Init scripts

If you are using one of Celery's generic init scripts, edit the script and wrap the celery command that is called when the script is used. This command usually looks like:


To add the agent’s wrapper script, change the CELERY_BIN variable to the following, where some/path/ is your actual path to the file or package:

CELERY_BIN=${CELERY_BIN:-"NEW_RELIC_CONFIG_FILE=/some/path/newrelic.ini /some/path/bin/newrelic-admin run-program /some/path/bin/celery"}

With this change, every time CELERY_BIN is called, it will be called with the agent wrapper script around the actual celery command.

Select the application name

The app_name setting in the Python agent configuration file sets the app name displayed in the New Relic One UI.

  • If your Python agent monitors Celery tasks and you set app_name to the same value used in your application agent's app_name, the data from both sources will be combined in the UI under that name.
  • If you set different names, the data appears separately in the UI as two different names.

By setting multiple app names in the agent config files, you can monitor both the combined data and the segregated data. Here's a common way to do this, using a Django application as an example:

Using multiple application names

For the agent monitoring the Django app, set the following:

app_name = Your_app_name (Django); Your_app_name (Combined)

For the agent monitoring Celery, set the following:

app_name = Your_app_name (Celery); Your_app_name (Combined)

This results in three displayed names in the UI:

  • Your_app_name (Combined), which combines data from both Celery and the Django application
  • Your_app_name (Django), which shows the Django app data
  • Your_app_name (Celery), which shows the Celery data

Ignore task retry errors

When using Celery, a task can possibly fail and raise a celery.exceptions:Retry or celery.exceptions:RetryTaskError exception. The exception depends on which version of Celery is used.

To ignore these errors, set this from the New Relic One Application settings UI or from the agent config file. UI changes override config file changes per the configuration precedence rules.

To use ignore error settings from the UI:

  1. From, select APM > (selected app) > Settings > Application.
  2. Select Server-side agent configuration.
  3. From Error collection, enter the errors you want to ignore, separated by commas.

To ignore these errors using the agent config file, use the ignore_errors setting and a space-separated list of exceptions:

error_collector.ignore_errors = celery.exceptions:Retry celery.exceptions:RetryTaskError


When a Celery worker process is killed suddenly, the agent is not able to complete its normal shutdown process, which means its final data payload is not sent. This results in the agent reporting fewer Celery transactions than expected or no transactions at all.

This may occur when using the CELERYD_MAX_TASKS_PER_CHILD setting, which defines the maximum number of tasks a pool worker process can execute before it's replaced with a new one. If used, the worker is forcibly shut down when that limit is reached, which means that that data is not recorded by the agent. For example, if MAX_TASKS_PER_CHILD = 1, this results in no data being reported.

How to troubleshoot this will depend on why you want to use the MAX_TASKS_PER_CHILD limit in your application.

  • To allow the normal shutdown process, return this to the default no-limit setting.
  • To lessen the impact of the problem, raise the MAX_TASKS_PER_CHILD limit.

For version or higher, the Python agent will shut down when the MAX_TASKS_PER_CHILD limit is reached. No data will be lost.

For more help

If you need more help, check out these support and learning resources: