Skip to content

Fix Sentry before_send and transport dotted-path config resolution in… - #69504

Open
Adityakk9031 wants to merge 2 commits into
apache:mainfrom
Adityakk9031:#69464
Open

Adityakk9031 wants to merge 2 commits into
apache:mainfrom
Adityakk9031:#69464

Conversation

@Adityakk9031

@Adityakk9031 Adityakk9031 commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

close:#69464

A regression in the Task SDK prevented the [sentry] before_send and [sentry] transport configuration options (when set to dotted-path strings) from being resolved to their actual callables. Instead, they were passed as raw strings to sentry_sdk.init(), which led to Sentry silently dropping all events.

This PR ensures that these configuration options are unconditionally resolved using conf.getimport to callable objects before initializing the Sentry SDK.

@boring-cyborg

boring-cyborg Bot commented Jul 7, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

@potiuk potiuk added the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Jul 11, 2026

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Sentry fix itself is correct — before_send and transport were being passed to sentry_sdk.init() as dotted-path strings rather than resolved callables, so neither ever took effect. Using conf.getimport and updating the tests to compare against import_string(...) is right, and I checked the UNSUPPORTED_SENTRY_OPTIONS warning survived the restructuring — it did.

My problem is scope. The title says "Fix Sentry before_send and transport dotted-path config resolution", but the PR also contains unrelated Windows-compatibility work in three other places: read_text(encoding="utf-8") across common_prek_utils.py, an os.register_at_fork guard in shared/observability/.../stats.py, and a fake fcntl module in a task-sdk conftest.

Those are a different change with a different risk profile, and one of them I'd block on its own merits (inline). Please split: land the Sentry fix on its own, and take the Windows work to a separate PR where it can be discussed properly — including the prior question of whether running these components on Windows is something Airflow intends to support at all, which isn't a decision that should ride in on a Sentry bugfix.


Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting

@Adityakk9031

Adityakk9031 commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Thankyou @potiuk for the detailed review — the feedback is well-taken on all points.

Done:

Sentry fix only — the PR has been stripped down to exactly the 2 files you approved: sentry/configured.py (removing the dead if/else branch so conf.getimport runs unconditionally) and test_sentry.py (asserting resolved callables via import_string instead of raw strings). Branch is also rebased onto the latest main.

Windows-compat work split out — the three unrelated changes (common_prek_utils.py encoding, os.register_at_fork guard, and the conftest platform handling) have been moved to a separate PR on branch windows-compat-fixes. The conftest approach has also been corrected per your inline comment — instead of installing a no-op fcntl stub, test_supervisor.py and test_task_runner.py now carry a pytestmark = pytest.mark.skipif(sys.platform == "win32", ...) so POSIX-dependent tests are skipped honestly on Windows and continue to run normally on Linux CI.

This PR now only contains the Sentry bugfix

@eladkal
eladkal requested a review from potiuk August 20, 2026 10:25
@eladkal eladkal added this to the Airflow 3.3.2 milestone Aug 20, 2026
Comment on lines +90 to +98
if before_send := conf.getimport("sentry", "before_send", fallback=None):
sentry_config_opts["before_send"] = before_send
else:
dsn = None
if before_send := conf.getimport("sentry", "before_send", fallback=None):
sentry_config_opts["before_send"] = before_send
if transport := conf.getimport("sentry", "transport", fallback=None):
sentry_config_opts["transport"] = transport
sentry_config_opts.pop("before_send", None)

if transport := conf.getimport("sentry", "transport", fallback=None):
sentry_config_opts["transport"] = transport
else:
sentry_config_opts.pop("transport", None)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified by using the import_string method

from airflow.sdk._shared.module_loading import import_string and then:

Suggested change
if before_send := conf.getimport("sentry", "before_send", fallback=None):
sentry_config_opts["before_send"] = before_send
else:
dsn = None
if before_send := conf.getimport("sentry", "before_send", fallback=None):
sentry_config_opts["before_send"] = before_send
if transport := conf.getimport("sentry", "transport", fallback=None):
sentry_config_opts["transport"] = transport
sentry_config_opts.pop("before_send", None)
if transport := conf.getimport("sentry", "transport", fallback=None):
sentry_config_opts["transport"] = transport
else:
sentry_config_opts.pop("transport", None)
if before_send := sentry_config_opts.pop("before_send", None):
sentry_config_opts["before_send"] = import_string(before_send)
if transport := sentry_config_opts.pop("transport", None):
sentry_config_opts["transport"] = import_string(transport)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, switched to import_string on the popped values (pushed). I could not run the Sentry tests locally on Windows because the _shared symlinks do not resolve, so I am relying on CI.

@ashb
ashb self-requested a review August 20, 2026 10:32
else:
dsn = None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was dsn being cleared here before? Any idea?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why shouldn't it be cleared now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dsn is popped because sentry_sdk.init(dsn=dsn, integrations=integrations, **sentry_config_opts) would otherwise raise TypeError: got multiple values for keyword argument 'dsn'. It also lets the deprecated sentry_dsn fall back to dsn. That behaviour is unchanged here, and it should still be popped, so that the explicit dsn= argument is the only source.

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scope problem is fully resolved — this is down to the two Sentry files, and the fcntl stub, the os.register_at_fork guard in shared/observability and the read_text(encoding=...) changes are all gone. Thanks for splitting it; that was the right call and it made this reviewable.

The fix itself reads correctly now. before_send and transport resolve through conf.getimport on every path rather than only in the branch that ran when the [sentry] section happened to be empty, and the UNSUPPORTED_SENTRY_OPTIONS warning moved out with it so it fires in all cases too. The else: pop(...) branches are worth keeping — they cover an option that is set but empty, which would otherwise pass an empty string into sentry_sdk.init().

Approving to clear my earlier changes-requested, but this should not merge yet — @ashb has two open threads and they need his sign-off, not mine.

@Adityakk9031 the ball is with you on those; they have been waiting since 20 August and I do not think you have seen them. On the second one I can at least give you the history: dsn is popped out of sentry_config_opts because the call is sentry_sdk.init(dsn=dsn, integrations=integrations, **sentry_config_opts), so leaving it in the dict raises TypeError: got multiple values for keyword argument 'dsn'. As far as I can see your version still pops it at new_way_dsn = sentry_config_opts.pop("dsn", None), so that behaviour is unchanged — worth saying so on the thread.

On the first thread, conf.getimport vs import_string on the popped value: both work, and the argument for conf.getimport is that it routes through the secrets backends and env-var overrides the way every other config read does. That is worth putting to @ashb rather than just switching.


Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting

@Adityakk9031

Copy link
Copy Markdown
Contributor Author

Hey @ashb, thanks for the earlier review. I've replied on both threads: switched to import_string as you suggested (88768c0), and dsn is still popped so sentry_sdk.init(dsn=..., **opts) doesn't hit a duplicate-argument TypeError.

@potiuk's point about conf.getimport going through secrets backends and env overrides is worth a quick look from your side too. Happy to go either way if you prefer that.

Could you take another look when you get a chance? Also, just so it's visible: this is the actual fix for #69464, which got auto-closed by #73679 by mistake. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:dev-tools area:task-sdk ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants