Skip to content

feat(integrations): Add on-demand source context fetching from SCM integrations#110324

Merged
mujacica merged 15 commits into
masterfrom
feat/scm-source-context-backend
Mar 31, 2026
Merged

feat(integrations): Add on-demand source context fetching from SCM integrations#110324
mujacica merged 15 commits into
masterfrom
feat/scm-source-context-backend

Conversation

@mujacica

@mujacica mujacica commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

When stack trace frames lack inline source context, this feature fetches the file from the configured SCM integration (GitHub, GitLab, Perforce) and returns the surrounding lines via a new API endpoint.

  • New endpoint: /projects/{org}/{project}/stacktrace-source-context/
  • New utility: fetch_source_context_from_scm() with caching
  • Feature-flagged behind organizations:scm-source-context

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 10, 2026
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Mar 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚨 Warning: This pull request contains Frontend and Backend changes!

It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently.

Have questions? Please ask in the #discuss-dev-infra channel.

Comment thread src/sentry/integrations/utils/source_context.py Outdated
Comment thread src/sentry/integrations/utils/source_context.py Outdated
@github-actions

github-actions Bot commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on 281ff38 in this run:

tests/sentry/integrations/utils/test_source_context.py::FetchSourceContextTest::test_invalid_line_numberlog
tests/sentry/integrations/utils/test_source_context.py:48: in setUp
    super().setUp()
src/sentry/testutils/cases.py:1009: in setUp
    provider_key=self.provider.key,
E   AttributeError: 'str' object has no attribute 'key'
tests/sentry/integrations/utils/test_source_context.py::FetchSourceContextTest::test_file_not_foundlog
tests/sentry/integrations/utils/test_source_context.py:48: in setUp
    super().setUp()
src/sentry/testutils/cases.py:1009: in setUp
    provider_key=self.provider.key,
E   AttributeError: 'str' object has no attribute 'key'
tests/sentry/integrations/utils/test_source_context.py::FetchSourceContextTest::test_missing_line_numberlog
tests/sentry/integrations/utils/test_source_context.py:48: in setUp
    super().setUp()
src/sentry/testutils/cases.py:1009: in setUp
    provider_key=self.provider.key,
E   AttributeError: 'str' object has no attribute 'key'
tests/sentry/integrations/utils/test_source_context.py::FormatContextTest::test_format_context_none_context_linelog
src/sentry/testutils/cases.py:1009: in setUp
    provider_key=self.provider.key,
src/sentry/testutils/cases.py:992: in provider
    raise NotImplementedError(f"implement for {type(self).__module__}.{type(self).__name__}")
E   NotImplementedError: implement for test_source_context.FormatContextTest
tests/sentry/integrations/utils/test_source_context.py::FetchSourceContextTest::test_successful_fetchlog
tests/sentry/integrations/utils/test_source_context.py:48: in setUp
    super().setUp()
src/sentry/testutils/cases.py:1009: in setUp
    provider_key=self.provider.key,
E   AttributeError: 'str' object has no attribute 'key'
tests/sentry/integrations/utils/test_source_context.py::FetchSourceContextTest::test_line_out_of_rangelog
tests/sentry/integrations/utils/test_source_context.py:48: in setUp
    super().setUp()
src/sentry/testutils/cases.py:1009: in setUp
    provider_key=self.provider.key,
E   AttributeError: 'str' object has no attribute 'key'
tests/sentry/integrations/utils/test_source_context.py::FetchSourceContextTest::test_no_code_mapping_matchlog
tests/sentry/integrations/utils/test_source_context.py:48: in setUp
    super().setUp()
src/sentry/testutils/cases.py:1009: in setUp
    provider_key=self.provider.key,
E   AttributeError: 'str' object has no attribute 'key'
tests/sentry/integrations/utils/test_source_context.py::FetchSourceContextTest::test_get_client_exceptionlog
tests/sentry/integrations/utils/test_source_context.py:48: in setUp
    super().setUp()
src/sentry/testutils/cases.py:1009: in setUp
    provider_key=self.provider.key,
E   AttributeError: 'str' object has no attribute 'key'
tests/sentry/integrations/utils/test_source_context.py::FormatContextTest::test_format_context_utf8_decodelog
src/sentry/testutils/cases.py:1009: in setUp
    provider_key=self.provider.key,
src/sentry/testutils/cases.py:992: in provider
    raise NotImplementedError(f"implement for {type(self).__module__}.{type(self).__name__}")
E   NotImplementedError: implement for test_source_context.FormatContextTest
tests/sentry/integrations/utils/test_source_context.py::FetchSourceContextTest::test_cachinglog
tests/sentry/integrations/utils/test_source_context.py:48: in setUp
    super().setUp()
src/sentry/testutils/cases.py:1009: in setUp
    provider_key=self.provider.key,
E   AttributeError: 'str' object has no attribute 'key'
tests/sentry/integrations/utils/test_source_context.py::FetchSourceContextTest::test_get_file_not_supportedlog
tests/sentry/integrations/utils/test_source_context.py:48: in setUp
    super().setUp()
src/sentry/testutils/cases.py:1009: in setUp
    provider_key=self.provider.key,
E   AttributeError: 'str' object has no attribute 'key'
tests/sentry/integrations/utils/test_source_context.py::FormatContextTest::test_format_context_basiclog
src/sentry/testutils/cases.py:1009: in setUp
    provider_key=self.provider.key,
src/sentry/testutils/cases.py:992: in provider
    raise NotImplementedError(f"implement for {type(self).__module__}.{type(self).__name__}")
E   NotImplementedError: implement for test_source_context.FormatContextTest
tests/sentry/integrations/utils/test_source_context.py::FetchSourceContextTest::test_integration_not_foundlog
tests/sentry/integrations/utils/test_source_context.py:48: in setUp
    super().setUp()
src/sentry/testutils/cases.py:1009: in setUp
    provider_key=self.provider.key,
E   AttributeError: 'str' object has no attribute 'key'
tests/sentry/integrations/utils/test_source_context.py::FetchSourceContextTest::test_rate_limitedlog
tests/sentry/integrations/utils/test_source_context.py:48: in setUp
    super().setUp()
src/sentry/testutils/cases.py:1009: in setUp
    provider_key=self.provider.key,
E   AttributeError: 'str' object has no attribute 'key'
tests/sentry/integrations/utils/test_source_context.py::FormatContextTest::test_format_context_no_pre_or_postlog
src/sentry/testutils/cases.py:1009: in setUp
    provider_key=self.provider.key,
src/sentry/testutils/cases.py:992: in provider
    raise NotImplementedError(f"implement for {type(self).__module__}.{type(self).__name__}")
E   NotImplementedError: implement for test_source_context.FormatContextTest
tests/sentry/integrations/utils/test_source_context.py::FetchSourceContextTest::test_cache_key_uniquenesslog
tests/sentry/integrations/utils/test_source_context.py:48: in setUp
    super().setUp()
src/sentry/testutils/cases.py:1009: in setUp
    provider_key=self.provider.key,
E   AttributeError: 'str' object has no attribute 'key'

@github-actions

Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on 3a1e84e in this run:

tests/sentry/integrations/utils/test_source_context.py::FetchSourceContextTest::test_no_code_mapping_matchlog
tests/sentry/integrations/utils/test_source_context.py:98: in test_no_code_mapping_match
    result = fetch_source_context_from_scm([self.code_mapping], ctx)
src/sentry/integrations/utils/source_context.py:143: in fetch_source_context_from_scm
    file_content = client.get_file(config.repository, src_path, ref)
E   AttributeError: 'NoneType' object has no attribute 'get_file'

@mujacica mujacica marked this pull request as ready for review March 17, 2026 11:02
@mujacica mujacica requested review from a team as code owners March 17, 2026 11:02
@scttcper scttcper requested review from a team and oioki March 17, 2026 20:56

@oioki oioki left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved under assumption that the feature will be enabled for specific customers who asked for it (feature flag or org/project setting that is disabled by default).

@armenzg armenzg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As a concept, this makes sense 🎉
We will need the org setting or project setting to enable fetching source context.

Comment thread src/sentry/issues/endpoints/project_stacktrace_source_context.py
Comment thread src/sentry/integrations/utils/source_context.py
Comment thread src/sentry/issues/endpoints/project_stacktrace_source_context.py Outdated
Comment thread src/sentry/integrations/utils/source_context.py Outdated
Comment thread src/sentry/integrations/utils/source_context.py Outdated
Comment thread src/sentry/integrations/utils/source_context.py Outdated
Comment thread src/sentry/core/endpoints/project_details.py
Comment thread src/sentry/integrations/utils/source_context.py
Comment thread src/sentry/integrations/utils/source_context.py

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

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 1 potential issue.

Fix All in Cursor

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

Comment thread src/sentry/integrations/utils/source_context.py
@mujacica mujacica merged commit f93bbec into master Mar 31, 2026
109 of 110 checks passed
@mujacica mujacica deleted the feat/scm-source-context-backend branch March 31, 2026 08:58
dashed pushed a commit that referenced this pull request Apr 1, 2026
…tegrations (#110324)

When stack trace frames lack inline source context, this feature fetches
the file from the configured SCM integration (GitHub, GitLab, Perforce)
and returns the surrounding lines via a new API endpoint.

- New endpoint: /projects/{org}/{project}/stacktrace-source-context/
- New utility: fetch_source_context_from_scm() with caching
- Feature-flagged behind organizations:scm-source-context

---------

Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants