Repository navigation
Conversation
A task runs in its own Sentry isolation scope, opened in _execute_activation. The failure reports in run_worker ran after that scope had closed. So the tags, contexts and trace that a task set did not reach the task's error events. Open the task's isolation scope in run_worker, around the task call and the failure reports. Each task still gets a fresh fork of the worker scope, so nothing reaches the next task.
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.
Bottom line: The worker now reports a task failure inside the task's own Sentry isolation scope. Failure events then carry the task's tags, contexts and trace, in every app that uses this client.
extrafields, fingerprints, transaction names (fix(worker): Attribute captured task errors to the current task #818), retry decisions, task status or metrics. Scope data does not reach the next task.sentry_sdk.set_level()) now applies to all of its failure events. A fingerprint that the task sets applies to the ordinary failure event only; the timeout and no-retries reports keep their own. Thetaskworker.task.failed,.retry_exhaustedand.retryrecords in Sentry Logs now carry the task's trace id and scope attributes.Cause
_execute_activationopens the task's isolation scope (workerchild.py:670).set_tag()andset_context()in the task write to it. A raised exception leaves thatwithblock, so the SDK restores the worker scope. Thenrun_workerreports the timeout (:511-522), no retries remaining (:553-573) or other failure (:583-587) in a fork of the worker scope. The task's data and trace are gone.Fix
run_workeropens the task's isolation scope around the task call and theexceptblocks._execute_activationdoes not open one. The nestedisolation_scope()blocks in the reports stay and now fork the task scope. Review with whitespace hidden: thetryblock moves one indent level.The retry log is in the same
exceptblock, so it also runs in the task scope. It is an info log and makes no error event.Tests
The new example task
examples.taggedsets a tag and a context, then passes, raises or sleeps.test_child_process_error_event_has_task_scope_data(exception, retry-exhausted, timeout): the event carries the task's tag, context and trace id. Red onmain, green here.test_child_process_task_scope_data_does_not_reach_next_task(after-success, after-failure): the next task's event has none of the first task's data. Passes onmainand here; fails with no task scope at all.main: 310). pre-commit (black, isort, flake8, mypy) passes.Test output