Repository navigation
Fix Sentry before_send and transport dotted-path config resolution in… - #69504
Adityakk9031 wants to merge 2 commits into
Conversation
|
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
|
potiuk
left a comment
There was a problem hiding this comment.
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
|
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 |
| 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) |
There was a problem hiding this comment.
This can be simplified by using the import_string method
from airflow.sdk._shared.module_loading import import_string and then:
| 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) |
There was a problem hiding this comment.
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.
| else: | ||
| dsn = None |
There was a problem hiding this comment.
Why was dsn being cleared here before? Any idea?
There was a problem hiding this comment.
And why shouldn't it be cleared now?
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
|
Hey @ashb, thanks for the earlier review. I've replied on both threads: switched to @potiuk's point about 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! |
close:#69464
A regression in the Task SDK prevented the
[sentry] before_sendand[sentry] transportconfiguration options (when set to dotted-path strings) from being resolved to their actual callables. Instead, they were passed as raw strings tosentry_sdk.init(), which led to Sentry silently dropping all events.This PR ensures that these configuration options are unconditionally resolved using
conf.getimportto callable objects before initializing the Sentry SDK.