Skip to content

Isolate Sentry instrumentation from task run#67505

Open
potiuk wants to merge 1 commit into
apache:mainfrom
potiuk:isolate-sentry-instrumentation-from-task-run
Open

Isolate Sentry instrumentation from task run#67505
potiuk wants to merge 1 commit into
apache:mainfrom
potiuk:isolate-sentry-instrumentation-from-task-run

Conversation

@potiuk
Copy link
Copy Markdown
Member

@potiuk potiuk commented May 25, 2026

In ConfiguredSentry.enrich_errors, prepare_to_enrich_errors, add_tagging and add_breadcrumbs ran either outside any try block (line 142, pre-fix) or inside 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 was indistinguishable from a real task failure.
  • The wrapped run never executed — instrumentation could effectively prevent the task from running.

Reported as F-006 in the apache/tooling-agents L3 task-sdk sweep 0920c77.

Change

Wrap each instrumentation step (prepare_to_enrich_errors, add_tagging, add_breadcrumbs) in its own try/except and log a structured warning on failure (sentry_prepare_failed, sentry_add_tagging_failed, sentry_add_breadcrumbs_failed). The wrapped run still runs inside sentry_sdk.new_scope and its exceptions are captured via sentry_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 wrapped run() 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_exception is called, exception re-raised.
  • prek run ruff clean.
  • prek run mypy-task-sdk clean.
  • Full test_sentry.py suite: 10 passed.

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 4.7)

Generated-by: Claude Code (Opus 4.7) following the guidelines

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant