From d536f9fbfc2bab74293d9fb56fb383193d4a4c8b Mon Sep 17 00:00:00 2001 From: Bolgov Andrey Date: Tue, 19 May 2020 18:19:10 +0300 Subject: [PATCH] Support extra config options for Sentry For now only dsn can be configured through the airflow.cfg. Need support 'http_proxy' option for example (it can't be configured through the environment variables). This change implements solution for supporting all existed (and maybe future) options for sentry configuration. --- airflow/config_templates/config.yml | 6 ++++- airflow/config_templates/default_airflow.cfg | 6 ++++- airflow/sentry.py | 26 +++++++++++++++++--- docs/errors.rst | 3 +++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/airflow/config_templates/config.yml b/airflow/config_templates/config.yml index e706c57fb8bcc..8fb14f3c68784 100644 --- a/airflow/config_templates/config.yml +++ b/airflow/config_templates/config.yml @@ -1124,7 +1124,11 @@ default: "airflow@example.com" - name: sentry description: | - Sentry (https://docs.sentry.io) integration + Sentry (https://docs.sentry.io) integration. Here you can supply + additional configuration options based on the Python platform. See: + https://docs.sentry.io/error-reporting/configuration/?platform=python. + Unsupported options: ``integrations``, ``in_app_include``, ``in_app_exclude``, + ``ignore_errors``, ``before_breadcrumb``, ``before_send``, ``transport``. options: - name: sentry_dsn description: ~ diff --git a/airflow/config_templates/default_airflow.cfg b/airflow/config_templates/default_airflow.cfg index 6cd5033ad26cb..ab157f84bcb83 100644 --- a/airflow/config_templates/default_airflow.cfg +++ b/airflow/config_templates/default_airflow.cfg @@ -547,7 +547,11 @@ smtp_mail_from = airflow@example.com [sentry] -# Sentry (https://docs.sentry.io) integration +# Sentry (https://docs.sentry.io) integration. Here you can supply +# additional configuration options based on the Python platform. See: +# https://docs.sentry.io/error-reporting/configuration/?platform=python. +# Unsupported options: ``integrations``, ``in_app_include``, ``in_app_exclude``, +# ``ignore_errors``, ``before_breadcrumb``, ``before_send``, ``transport``. sentry_dsn = [celery] diff --git a/airflow/sentry.py b/airflow/sentry.py index f5106f8597cf2..51b38d294749e 100644 --- a/airflow/sentry.py +++ b/airflow/sentry.py @@ -67,6 +67,11 @@ class ConfiguredSentry(DummySentry): ) SCOPE_CRUMBS = frozenset(("task_id", "state", "operator", "duration")) + UNSUPPORTED_SENTRY_OPTIONS = frozenset( + ("integrations", "in_app_include", "in_app_exclude", "ignore_errors", + "before_breadcrumb", "before_send", "transport") + ) + def __init__(self): """ Initialize the Sentry SDK. @@ -86,13 +91,28 @@ def __init__(self): sentry_celery = CeleryIntegration() integrations.append(sentry_celery) - dsn = conf.get("sentry", "sentry_dsn") + dsn = None + sentry_config_opts = conf.getsection("sentry") or {} + if sentry_config_opts: + old_way_dsn = sentry_config_opts.pop("sentry_dsn", None) + new_way_dsn = sentry_config_opts.pop("dsn", None) + # supported backward compability with old way dsn option + dsn = old_way_dsn or new_way_dsn + + unsupported_options = self.UNSUPPORTED_SENTRY_OPTIONS.intersection( + sentry_config_opts.keys()) + if unsupported_options: + log.warning( + "There are unsupported options in [sentry] section: %s", + ", ".join(unsupported_options) + ) + if dsn: - init(dsn=dsn, integrations=integrations) + init(dsn=dsn, integrations=integrations, **sentry_config_opts) else: # Setting up Sentry using environment variables. log.debug("Defaulting to SENTRY_DSN in environment.") - init(integrations=integrations) + init(integrations=integrations, **sentry_config_opts) def add_tagging(self, task_instance): """ diff --git a/docs/errors.rst b/docs/errors.rst index 9809d0f28d7a8..716add82e26dd 100644 --- a/docs/errors.rst +++ b/docs/errors.rst @@ -39,6 +39,9 @@ Add your ``SENTRY_DSN`` to your configuration file e.g. ``airflow.cfg`` under `` .. note:: If this value is not provided, the SDK will try to read it from the ``SENTRY_DSN`` environment variable. +You can supply `additional configuration options `__ based on the Python platform via [sentry] section. +Unsupported options: ``integrations``, ``in_app_include``, ``in_app_exclude``, ``ignore_errors``, ``before_breadcrumb``, ``before_send``, ``transport``. + Tags -----