Skip to content

ref(seer): Propagate viewer_context to background tasks and utilities#109724

Merged
azulus merged 3 commits intomasterfrom
viewer-context/tasks-utilities
Mar 4, 2026
Merged

ref(seer): Propagate viewer_context to background tasks and utilities#109724
azulus merged 3 commits intomasterfrom
viewer-context/tasks-utilities

Conversation

@azulus
Copy link
Member

@azulus azulus commented Mar 2, 2026

Pass SeerViewerContext to Seer API wrapper call sites in background tasks and utility modules.

PR #109697 added an optional viewer_context parameter to all Seer API wrapper functions. This PR updates:

  • context_engine_index.py: Pass organization_id from org_id param
  • seer_explorer_index.py: Pass organization_id from project tuples
  • trace_summary.py: Pass organization_id + optional user_id (when user is not None/anonymous)
  • supergroups.py: Pass organization_id from param
  • Skipped: seer_models.py (no auth), uptime/seer_assertions.py (no context)

No behavior change — viewer_context defaults to None which preserves existing behavior.

Co-Authored-By: Claude noreply@anthropic.com

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 2, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

Backend Test Failures

Failures on 200f9ab in this run:

tests/sentry/seer/test_trace_summary.py::TraceSummaryTest::test_get_trace_summary_successlog
tests/sentry/seer/test_trace_summary.py:134: in test_get_trace_summary_success
    mock_call_seer.assert_called_once_with(self.trace_id, self.trace_tree, False)
/opt/hostedtoolcache/Python/3.13.1/x64/lib/python3.13/unittest/mock.py:989: in assert_called_once_with
    return self.assert_called_with(*args, **kwargs)
/opt/hostedtoolcache/Python/3.13.1/x64/lib/python3.13/unittest/mock.py:977: in assert_called_with
    raise AssertionError(_error_message()) from cause
E   AssertionError: expected call not found.
E   Expected: _call_seer('trace123', [{'description': 'http.request', 'name': 'GET *', 'event_id': 'span1', 'event_type': 'span', 'project_id': 1, 'project_slug': 'test-project', 'start_timestamp': datetime.datetime(2023, 1, 1, 0, 0), 'transaction': 'test_transaction', 'children': [], 'errors': [], 'occurrences': [], 'duration': 100.0, 'end_timestamp': datetime.datetime(2023, 1, 1, 0, 0, 1), 'measurements': {}, 'op': 'http.request', 'parent_span_id': None, 'profile_id': '', 'profiler_id': '', 'sdk_name': 'test_sdk', 'is_transaction': True, 'transaction_id': '11111111111111111111111111111111'}, {'description': 'db.query', 'name': 'SELECT users', 'event_id': 'span2', 'event_type': 'span', 'project_id': 1, 'project_slug': 'test-project', 'start_timestamp': datetime.datetime(2023, 1, 1, 0, 0), 'transaction': 'test_transaction', 'children': [], 'errors': [], 'occurrences': [], 'duration': 50.0, 'end_timestamp': datetime.datetime(2023, 1, 1, 0, 0, 1), 'measurements': {}, 'op': 'db.query', 'parent_span_id': None, 'profile_id': '', 'profiler_id': '', 'sdk_name': 'test_sdk', 'is_transaction': False, 'transaction_id': '11111111111111111111111111111111'}], False)
E     Actual: _call_seer('trace123', [{'description': 'http.request', 'name': 'GET *', 'event_id': 'span1', 'event_type': 'span', 'project_id': 1, 'project_slug': 'test-project', 'start_timestamp': datetime.datetime(2023, 1, 1, 0, 0), 'transaction': 'test_transaction', 'children': [], 'errors': [], 'occurrences': [], 'duration': 100.0, 'end_timestamp': datetime.datetime(2023, 1, 1, 0, 0, 1), 'measurements': {}, 'op': 'http.request', 'parent_span_id': None, 'profile_id': '', 'profiler_id': '', 'sdk_name': 'test_sdk', 'is_transaction': True, 'transaction_id': '11111111111111111111111111111111'}, {'description': 'db.query', 'name': 'SELECT users', 'event_id': 'span2', 'event_type': 'span', 'project_id': 1, 'project_slug': 'test-project', 'start_timestamp': datetime.datetime(2023, 1, 1, 0, 0), 'transaction': 'test_transaction', 'children': [], 'errors': [], 'occurrences': [], 'duration': 50.0, 'end_timestamp': datetime.datetime(2023, 1, 1, 0, 0, 1), 'measurements': {}, 'op': 'db.query', 'parent_span_id': None, 'profile_id': '', 'profiler_id': '', 'sdk_name': 'test_sdk', 'is_transaction': False, 'transaction_id': '11111111111111111111111111111111'}], False, viewer_context={'organization_id': 4557725066526720, 'user_id': 784})

@azulus azulus marked this pull request as ready for review March 2, 2026 22:47
@azulus azulus requested a review from a team as a code owner March 2, 2026 22:47
Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

azulus added 3 commits March 3, 2026 17:16
Pass SeerViewerContext to Seer API call sites in context engine index,
explorer index, trace summary, and supergroups. Tasks use org only,
trace summary uses org+optional user.
The test assertion for _call_seer now includes the viewer_context
keyword argument that is passed through from get_trace_summary.
- Fix multi-org batch: only set viewer_context when all projects in a
  batch share the same org_id, otherwise skip it
- Remove redundant `user is not None` check in trace_summary.py since
  user is guaranteed non-None after the AnonymousUser fallback
@azulus azulus force-pushed the viewer-context/tasks-utilities branch from 1b90307 to 0b18a1d Compare March 4, 2026 01:16
@azulus azulus merged commit 8eb2e64 into master Mar 4, 2026
76 checks passed
@azulus azulus deleted the viewer-context/tasks-utilities branch March 4, 2026 01:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants