def init_app(self, app):
        self.app = app

        if self.app.config["SENTRY_DSN"]:
            sentry_celery._make_event_processor = self.custom_event_processor
            sentry_sdk.init(
                dsn=self.app.config["SENTRY_DSN"],
                integrations=[sentry_celery.CeleryIntegration()],
            )
Beispiel #2
0
def configure():
    """Configure Sentry logging integration for Celery.

    See the `official instructions for Celery integration
    <https://docs.sentry.io/platforms/python/celery/>`_.

    Notes
    -----
    Add the API key username/pasword pair to your netrc file.

    """
    # Catching NetrcParseError confuses sphinx.
    if SPHINX:  # pragma: no cover
        return

    # Delayed import
    from .. import app

    scheme, netloc, *rest = urlparse(DSN)

    try:
        auth = netrc().authenticators(netloc)
        if not auth:
            raise ValueError('No netrc entry found for {}'.format(netloc))
    except (NetrcParseError, OSError, ValueError):
        log.exception(
            'Disabling Sentry integration because we could not load '
            'the username and password for %s from the netrc file', netloc)
        return

    # The "legacy" Sentry DSN requires a "public key" and a "private key",
    # which are transmitted as the username and password in the URL.
    # However, as of Sentry 9, then "private key" part is no longer required.
    username, _, _ = auth
    dsn = urlunparse((scheme, '{}@{}'.format(username, netloc), *rest))
    version = 'gwcelery-{}'.format(_version.get_versions()['version'])
    environment = app.conf['sentry_environment']
    sentry_sdk.init(dsn,
                    environment=environment,
                    release=version,
                    integrations=[
                        celery.CeleryIntegration(),
                        condor.CondorIntegration(),
                        flask.FlaskIntegration(),
                        redis.RedisIntegration(),
                        requests.RequestsIntegration(),
                        subprocess.SubprocessIntegration(),
                        tornado.TornadoIntegration()
                    ])
Beispiel #3
0
def get_sentry_integrations() -> list:
    """
    Determine which Sentry SDK integrations to enable.
    """
    default = [
        django.DjangoIntegration(),
        # redis.RedisIntegration(),
    ]
    extra = []

    try:
        from sentry_sdk.integrations import celery
    except DidNotEnable:  # happens if the celery import fails by the integration
        pass
    else:
        extra.append(celery.CeleryIntegration())

    return [*default, *extra]
Beispiel #4
0
HIJACK_LOGOUT_REDIRECT_URL = reverse_lazy("admin:accounts_user_changelist")
# The Admin mixin is used because we use a custom User-model.
HIJACK_REGISTER_ADMIN = False
# This is a CSRF-security risk.
# See: http://django-hijack.readthedocs.io/en/latest/configuration/#allowing-get-method-for-hijack-views
HIJACK_ALLOW_GET_REQUESTS = True

# Sentry SDK
SENTRY_DSN = os.getenv("SENTRY_DSN")

SENTRY_SDK_INTEGRATIONS = [
    django.DjangoIntegration(),
    redis.RedisIntegration(),
]
if celery is not None:
    SENTRY_SDK_INTEGRATIONS.append(celery.CeleryIntegration())

if SENTRY_DSN:
    import sentry_sdk

    SENTRY_CONFIG = {
        "dsn": SENTRY_DSN,
        "release": os.getenv("VERSION_TAG", "VERSION_TAG not set"),
    }

    sentry_sdk.init(
        **SENTRY_CONFIG, integrations=SENTRY_SDK_INTEGRATIONS, send_default_pii=True
    )

# Elastic APM
Beispiel #5
0
# coding=utf-8

import os
from sentry_sdk import init as sentry_init
from sentry_sdk.integrations import celery as sentry_celery
from celery import Celery
from . import config


manager = Celery('app')
manager.config_from_object(config)
sentry_init(
    dsn=os.getenv('SENTRY_DSN'),
    integrations=(sentry_celery.CeleryIntegration(),)
)
Beispiel #6
0
import os
import sentry_sdk
from sentry_sdk.integrations import (
    celery,
    django,
    redis,
)

sentry_sdk.init(
    dsn=os.environ.get('SENTRY_DSN'),
    integrations=[
        celery.CeleryIntegration(),
        django.DjangoIntegration(),
        redis.RedisIntegration(),
    ],
    traces_sample_rate=1.0,
    # If you wish to associate users to errors (assuming you are using
    # django.contrib.auth) you may enable sending PII data.
    send_default_pii=True,
)