Skip to main content

instrument sql queries running on celery

Project description

celery-sqlcommenter

Attach SQL comments to correlate celery tasks with SQL statements.

This helps in easily correlating slow performance with async tasks and giving insights into backend database performance. In short it provides some observability into the state of your client-side applications and their impact on the database’s server-side.

When to use?

You're using celery with django, and want to trace the origin of database queries.

Does it replace / overlap sqlcommenter

No. I've been using sqlcommenter in production and it lacked the ability to annotate queries that were run in non-http context. Meaning all queries that originated from async flows were untagged.

This package fills that gap.

How to use

In a simple celery setup, just passing the BaseTask when declaring a celery object will do the job.

# if not using a base class, pass directly where you declare celery config
from celery_sqlcommenter import BaseTask
app = Celery("my-awsome-application", task_cls=BaseTask)

If you already have a custom BaseTask with specific functionality, replace the original celery.Task with celery_sqlcommenter.BaseTask

# old configuration
from celery import Task
class MyBaseTask(Task):

    # custom methods you've implemented
    def on_failure(self, exc, task_id, args, kwargs):
        pass


# simply replace Task with BaseTask provided by the package
from celery_sqlcommenter import BaseTask


# notice Task changed to BaseTask
class MyBaseTask(BaseTask):

    # custom methods you've implemented
    def on_failure(self, exc, task_id, args, kwargs):
        pass

Internally BaseTask inherits celery.Task so all functionality stays intact

How to install

Install the package from pypi

# vanilla
pip install celery-sqlcommenter

# poetry 
poetry add celery-sqlcommenter

How does it look live?

a simple celery task that takes a while

More Questions?

Please open an issue or drop a message on my socials, will be happy to help.

LinkedIn X

Project details


Download files

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

Source Distribution

celery_sqlcommenter-0.1.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

celery_sqlcommenter-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: celery_sqlcommenter-0.1.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.8.18

File hashes

Hashes for celery_sqlcommenter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9e8411507ef87f0910e1bf35c3dfbf8e4581f81cc30b1e5fb17ffdae8ad3b2cc
MD5 6f6e97f233feb8a7c9d0e86b8ad38f23
BLAKE2b-256 cf29adb18c005daba809eb5c29d35bad866f9e54d8a8c06ca956bfec00b3f5ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for celery_sqlcommenter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70c3a6ed38ffa4a5bfb1f74992c672fff304b25b9e82d4783365a72f52e63fba
MD5 fe34c201ed7ed17f5f76f23201d4732c
BLAKE2b-256 0074dec54829bf7b2ba3595bc4c6311d1e3ced98352ffec52e39266921975a5d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page