Isolate Sentry instrumentation from task run#67505
Open
potiuk wants to merge 1 commit into
Open
Conversation
In ``ConfiguredSentry.enrich_errors``, ``prepare_to_enrich_errors``, ``add_tagging`` and ``add_breadcrumbs`` ran inside (or alongside) the same try-block as the wrapped ``run(...)``. An exception raised by any of them propagated through the wrapper, so a failure in non-critical Sentry instrumentation looked indistinguishable from a real task failure and the wrapped ``run`` never executed. Wrap each instrumentation step in its own ``try/except`` and log a structured warning on failure. The wrapped ``run`` still runs inside ``sentry_sdk.new_scope`` and its exceptions are captured and re-raised — that part is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
ConfiguredSentry.enrich_errors,prepare_to_enrich_errors,add_taggingandadd_breadcrumbsran either outside any try block (line 142, pre-fix) or inside the same try-block as the wrappedrun(...). An exception raised by any of them propagated through the wrapper, so:runnever executed — instrumentation could effectively prevent the task from running.Reported as F-006 in the
apache/tooling-agentsL3 task-sdk sweep0920c77.Change
Wrap each instrumentation step (
prepare_to_enrich_errors,add_tagging,add_breadcrumbs) in its owntry/exceptand log a structured warning on failure (sentry_prepare_failed,sentry_add_tagging_failed,sentry_add_breadcrumbs_failed). The wrappedrunstill runs insidesentry_sdk.new_scopeand its exceptions are captured viasentry_sdk.capture_exception(e)and re-raised — that path is unchanged.Test plan
test_enrich_errors_isolates_instrumentation_from_task_run(parametrised across all three instrumentation steps) — asserts (a) the wrappedrun()still executes when each step raises, (b) the structured warning is emitted on the task log.test_enrich_errors_captures_and_reraises_task_failure— asserts the wrapped-run failure path is unchanged:sentry_sdk.capture_exceptionis called, exception re-raised.prek run ruffclean.prek run mypy-task-sdkclean.test_sentry.pysuite: 10 passed.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.7) following the guidelines