Python sentry_sdk.integrations.celery.CeleryIntegration() Examples

The following are 4 code examples of sentry_sdk.integrations.celery.CeleryIntegration(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sentry_sdk.integrations.celery , or try the search function .
Example #1
Source File: test_settings.py    From mitoc-trips with GNU General Public License v3.0 6 votes vote down vote up
def test_sentry_initialized_from_envvar(self):
        """ The DSN for Sentry comes from config. """
        fake_dsn = 'https://hex-code@sentry.io/123446'

        with mock.patch.dict('os.environ', {'RAVEN_DSN': fake_dsn}):
            with mock.patch.object(settings.sentry_sdk, 'init') as init_sentry:
                self._fresh_settings_load()
        init_sentry.assert_called_once_with(
            fake_dsn,
            integrations=[mock.ANY, mock.ANY],  # Django & Celery, checked separately
            send_default_pii=True,
        )
        integrations = init_sentry.call_args_list[0][1]['integrations']

        self.assertTrue(isinstance(integrations[0], DjangoIntegration))
        self.assertTrue(isinstance(integrations[1], CeleryIntegration)) 
Example #2
Source File: test_celery.py    From sentry-python with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def init_celery(sentry_init):
    def inner(propagate_traces=True, **kwargs):
        sentry_init(
            integrations=[CeleryIntegration(propagate_traces=propagate_traces)],
            **kwargs
        )
        celery = Celery(__name__)
        if VERSION < (4,):
            celery.conf.CELERY_ALWAYS_EAGER = True
        else:
            celery.conf.task_always_eager = True
        return celery

    return inner 
Example #3
Source File: sentry.py    From airflow with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        """
        Initialize the Sentry SDK.
        """
        ignore_logger("airflow.task")
        ignore_logger("airflow.jobs.backfill_job.BackfillJob")
        executor_name = conf.get("core", "EXECUTOR")

        sentry_flask = FlaskIntegration()

        # LoggingIntegration is set by default.
        integrations = [sentry_flask]

        if executor_name == "CeleryExecutor":
            from sentry_sdk.integrations.celery import CeleryIntegration

            sentry_celery = CeleryIntegration()
            integrations.append(sentry_celery)

        dsn = conf.get("sentry", "sentry_dsn")
        if dsn:
            init(dsn=dsn, integrations=integrations)
        else:
            # Setting up Sentry using environment variables.
            log.debug("Defaulting to SENTRY_DSN in environment.")
            init(integrations=integrations) 
Example #4
Source File: sentry_integration.py    From packit-service with MIT License 4 votes vote down vote up
def configure_sentry(
    runner_type: str,
    celery_integration: bool = False,
    flask_integration: bool = False,
    sqlalchemy_integration: bool = False,
) -> None:
    logger.debug(
        f"Setup sentry for {runner_type}: "
        f"celery_integration={celery_integration}, "
        f"flask_integration={flask_integration}, "
        f"sqlalchemy_integration={sqlalchemy_integration}"
    )

    secret_key = getenv("SENTRY_SECRET")
    if not secret_key:
        return

    # so that we don't have to have sentry sdk installed locally
    import sentry_sdk

    integrations = []

    if celery_integration:
        # https://docs.sentry.io/platforms/python/celery/
        from sentry_sdk.integrations.celery import CeleryIntegration

        integrations.append(CeleryIntegration())

    if flask_integration:
        # https://docs.sentry.io/platforms/python/flask/
        from sentry_sdk.integrations.flask import FlaskIntegration

        integrations.append(FlaskIntegration())

    if sqlalchemy_integration:
        # https://docs.sentry.io/platforms/python/sqlalchemy/
        from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration

        integrations.append(SqlalchemyIntegration())

    sentry_sdk.init(
        secret_key, integrations=integrations, environment=getenv("DEPLOYMENT"),
    )
    with sentry_sdk.configure_scope() as scope:
        scope.set_tag("runner-type", runner_type)