tlskr opened a new issue #21395:
URL: https://github.com/apache/airflow/issues/21395


   ### Apache Airflow version
   
   2.2.3 (latest released)
   
   ### What happened
   
   I have configured Airflow to set sentry_on and sentry_dsn through 
environment variables.  When I deliberately raise an Exception no error is sent 
to Sentry.
   
   I have tried patching Sentry.enrich_errors to log a call, but when patched 
nothing was logged when an exception is raised.
   
   ### What you expected to happen
   
   I expect the Airflow instance to send an error message to Sentry on an 
exception.
   
   When Sentry.enrich_errors is patched, I expect it to log a message when an 
exception is raised.
   
   ### How to reproduce
   
   I have set sentry_on and sentry_dsn in environment variables 
(AIRFLOW__SENTRY__SENTRY_ON and AIRFLOW__SENTRY__SENTRY_DSN), and these appear 
in the Airflow GUI Admin > Configuration display.
   
   I run the following code on my local instance to raise an exception.  
   
   Note:
   -- when the enrich_errors patch is commented out, no error message is sent 
to Sentry.
   -- I am confident in the sentry_dsn value, because our custom code sending 
to Sentry in on_failure_callback works.
   
   ```
   import logging
   from datetime import datetime, timedelta
   from functools import wraps
   
   from airflow import DAG
   from airflow.configuration import conf
   from airflow.exceptions import AirflowException
   from airflow.operators.python import PythonOperator
   from airflow.sentry import Sentry
   
   logging.info("sentry_on is %s" % str(conf.getboolean("sentry", "sentry_on", 
fallback=False)))
   
   
   class MySentry:
       def enrich_errors(self, func):
           """ Patch for enrich_errors to log if it has been called.  """
   
           @wraps(func)
           def wrapper(_self, *args, **kwargs):
               logging.info("MySentry.enrich_errors has been called")
               return func(_self, *args, **kwargs)
   
           return wrapper
   
   # Sentry.enrich_errors = MySentry.enrich_errors
   
   def throw_exception_function():
       raise Exception("still another exception thrown on purpose, no DAG or 
Task on_failure_callback, patch enrich_errors")
   
   
   with DAG(
       dag_id="deliberate_exception__patch_enrich_errors",
       default_args={
           "owner": "DAG owner",
           "depends_on_past": False,
           "start_date": datetime(2017, 1, 1),
           "retries": 0,
           "retry_delay": timedelta(minutes=0),
       },
       description="Deliberately throws exception without on_failure_callback 
for DAG or task; patches enrich_errors",
       schedule_interval=None,
       catchup=False,
   ) as dag:
   
       Sentry.enrich_errors = MySentry.enrich_errors
   
       exception_task = PythonOperator(
           task_id="exception_task",
           python_callable=throw_exception_function,
       )
   ```
   
   
   ### Operating System
   
   Linux and OSX
   
   ### Versions of Apache Airflow Providers
   
   apache-airflow-providers-amazon==2.4.0
   apache-airflow-providers-cncf-kubernetes==2.2.0
   apache-airflow-providers-datadog==2.0.1
   apache-airflow-providers-ftp==2.0.1
   apache-airflow-providers-http==2.0.1
   apache-airflow-providers-imap==2.1.0
   apache-airflow-providers-jdbc==2.0.1
   apache-airflow-providers-microsoft-azure==3.4.0
   apache-airflow-providers-mongo==2.2.0
   apache-airflow-providers-postgres==2.4.0
   apache-airflow-providers-sftp==2.1.1
   apache-airflow-providers-slack==4.1.0
   apache-airflow-providers-snowflake==2.3.1
   apache-airflow-providers-sqlite==2.0.1
   apache-airflow-providers-ssh==2.2.0
   
   ### Deployment
   
   Other Docker-based deployment
   
   ### Deployment details
   
   _No response_
   
   ### Anything else
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to