8000 Automatically create monitors when using Redbeat · Issue #2616 · getsentry/sentry-python · GitHub
[go: up one dir, main page]

Skip to content
Automatically create monitors when using Redbeat #2616
@bensaufley

Description

@bensaufley

Environment

SaaS (https://sentry.io/)

Steps to Reproduce

We're using Python with Celery and Redbeat and following the docs for setup. Using either the autodiscover or manual @monitor instrumentation outlined in the docs, we are not having monitors in our Sentry UI automatically created. But manually creating them confirms that the data does come into Sentry—as soon as they're created we can see data for them in the UI, but only from that point forward.

I've been talking to Sentry support about this and was asked to create an Issue. Unfortunately our repo is private but our setup is pretty straightforward. Here's the gist of what we've got:

requirements.txt:

celery==5.2.6
celery-redbeat==2.0.0

worker.py

from celery import Celery
from celery.signals import celeryd_init
from celery.schedules import crontab
import sentry_sdk
from sentry_sdk.crons.decorator import monitor
from sentry_sdk.integrations.celery import CeleryIntegration

from myco import _my_celery_task, get_env_var, LockInUse, get_redis_url

app = Celery(__name__, broker=get_redis_url(database='celery'))

@celeryd_init.connect
def init_sentry(**_kwargs):
    env = get_env_var('APP_ENV', False)
    if not env:
        print('APP_ENV not set, defaulting to development')
        env = 'development'
    if env not in ['development', 'test']:
        sentry_sdk.init(
            dsn="<DSN@ingest.sentry.io>", # obviously this is redacted

            environment=env,
            release=get_env_var('SENTRY_RELEASE_VERSION', False) or 'unknown',

            ignore_errors=[LockInUse],

            integrations=[CeleryIntegration()],

            # Set traces_sample_rate to 1.0 to capture 100%
            # of transactions for performance monitoring.
            # We recommend adjusting this value in production,
            traces_sample_rate=0.005,
        )

# ...


@app.task
@monitor(monitor_slug='my_celery_task')
def my_celery_task():
    return _my_celery_task()

# ...

app.conf.redbeat_redis_url = get_redis_url(database='celery')
app.conf.beat_scheduler = 'redbeat.RedBeatScheduler'
app.conf.beat_schedule = {
    'my-celery-task': {
        'task': 'worker.my_celery_task',
        'schedule': crontab(minute='0', hour='0', day_of_week='1'),
    },
    # ...
}

Expected Result

Cron job monitors are automatically created in Sentry on deploy, or at least when they execute

Actual Result

No monitors are created

Product Area

Crons

Link

No response

DSN

No response

Version

No response

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Waiting for: Product Owner

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0