Lwackp opened a new issue, #63357:
URL: https://github.com/apache/airflow/issues/63357

   ### Apache Airflow version
   
   3.1.7
   
   ### If "Other Airflow 3 version" selected, which one?
   
   _No response_
   
   ### What happened?
   
   The Sentry integration is not working on Airflow 3.1.7 when using the 
`KubernetesExecutor`. Task failures are not reported to Sentry despite correct 
configuration.
   
   This appears to be a continuation of #52368, which was fixed in PR #57032 
for the core task runner path. However, with `KubernetesExecutor`, tasks 
execute via `apache-airflow-task-sdk`, which has a different execution path 
that does not import `airflow.sentry`.
   
   **Environment**
   
   ```
     apache-airflow-core: 3.1.7
     apache-airflow-task-sdk: 1.1.7
     sentry-sdk: 2.54.0
     blinker: 1.9.0
     Executor: KubernetesExecutor
   ```
   
   **Configuration**
   
   ```
     AIRFLOW__SENTRY__SENTRY_ON=true
     AIRFLOW__SENTRY__SENTRY_DSN=<valid DSN>
   ```
   
   
   ### What you think should happen instead?
   
   Task failures should be automatically reported to Sentry when 
`sentry_on=true` and a valid DSN is configured, regardless of the executor type.
   
   PR #57032 restored the Sentry import in the core task runner, but the Task 
SDK (`apache-airflow-task-sdk`) used by `KubernetesExecutor` has a separate 
execution path that never imports `airflow.sentry`, so 
ConfiguredSentry.enrich_errors()` is never applied as a decorator on task  
execution.
   
   ### How to reproduce
   
   The following diagnostic tasks were run:
   
   1. ConfiguredSentry loads correctly when explicitly imported
   
   ```
     from airflow.sentry import Sentry
     print(type(Sentry))
     # <class 'airflow.sentry.ConfiguredSentry'>
   ```
   
     The config values are correct, `sentry_on` resolves to `True`, and the DSN 
is set.
   
     2. Nothing in the task execution path imports airflow.sentry
   
   ```
     # Checked the source of key modules for any reference to airflow.sentry:
     airflow.models.taskinstance: NO sentry import
     airflow.executors.base_executor: NO sentry import
     airflow.task.standard_task_runner: module does not exist in task SDK
   
     # airflow.sentry is not loaded during task execution:
     'airflow.sentry' in sys.modules: False
   ```
   
   The `enrich_errors` decorator in `ConfiguredSentry` is never applied because 
the module is never imported during task execution via the Task SDK.
   
   3. Manual `sentry_sdk.init()` works
   
   When explicitly initializing `sentry_sdk` and calling `capture_exception()` 
within a task, errors are successfully reported to Sentry. This confirms the 
DSN, network connectivity, and sentry-sdk installation are all correct.
   
   ```
     import sentry_sdk
     sentry_sdk.init(dsn=os.environ["AIRFLOW__SENTRY__SENTRY_DSN"])
     try:
         raise ValueError("test")
     except Exception as e:
         sentry_sdk.capture_exception(e)
         sentry_sdk.flush(timeout=5)
     # ✅ Error appears in Sentry
   ```
   
   ### Operating System
   
   Linux
   
   ### Versions of Apache Airflow Providers
   
   ```
   acryl-datahub-airflow-plugin              1.4.0.5
   apache-airflow                            3.1.7
   apache-airflow-core                       3.1.7
   apache-airflow-providers-amazon           9.21.0
   apache-airflow-providers-celery           3.15.2
   apache-airflow-providers-cncf-kubernetes  10.12.3
   apache-airflow-providers-common-compat    1.13.0
   apache-airflow-providers-common-io        1.7.1
   apache-airflow-providers-common-messaging 2.0.2
   apache-airflow-providers-common-sql       1.30.4
   apache-airflow-providers-docker           4.5.2
   apache-airflow-providers-elasticsearch    6.4.4
   apache-airflow-providers-fab              3.2.0
   apache-airflow-providers-ftp              3.14.1
   apache-airflow-providers-git              0.2.2
   apache-airflow-providers-google           19.5.0
   apache-airflow-providers-grpc             3.9.2
   apache-airflow-providers-hashicorp        4.4.3
   apache-airflow-providers-http             5.6.4
   apache-airflow-providers-microsoft-azure  12.10.3
   apache-airflow-providers-mysql            6.4.2
   apache-airflow-providers-odbc             4.11.1
   apache-airflow-providers-openlineage      2.10.1
   apache-airflow-providers-postgres         6.5.3
   apache-airflow-providers-redis            4.4.2
   apache-airflow-providers-sendgrid         4.2.1
   apache-airflow-providers-sftp             5.7.0
   apache-airflow-providers-slack            9.6.2
   apache-airflow-providers-smtp             2.4.2
   apache-airflow-providers-snowflake        6.9.0
   apache-airflow-providers-ssh              4.3.1
   apache-airflow-providers-standard         1.11.0
   apache-airflow-task-sdk                   1.1.7
   google-cloud-orchestration-airflow        1.19.0
   sentry-sdk                                2.54.0
   ```
   
   ### Deployment
   
   Official Apache Airflow Helm Chart
   
   ### Deployment details
   
   KubernetesExecutor
   
   ### 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