Skip to content

feat(core): Add read_scope for read-only scope access#1235

Open
bardiharborow wants to merge 2 commits into
getsentry:masterfrom
bardiharborow:feat/read-scope
Open

feat(core): Add read_scope for read-only scope access#1235
bardiharborow wants to merge 2 commits into
getsentry:masterfrom
bardiharborow:feat/read-scope

Conversation

@bardiharborow

Copy link
Copy Markdown

Hub::configure_scope clones the entire scope and writes it back under the hub's write lock, which is wasteful on hot paths that only need to read scope data (e.g. integrations resolving the current span per event).

This PR adds Hub::read_scope which provides read-only access without the clone and write-back, and the global sentry::read_scope exposes the same via the active hub, mirroring sentry::configure_scope. It also switches existing call sites where appropriate.

bardiharborow and others added 2 commits July 10, 2026 18:52
`Hub::configure_scope` clones the entire scope and writes it back under
the hub's write lock, which is wasteful on hot paths that only need to
read scope data (e.g. integrations resolving the current span per
event). `Hub::read_scope` provides read-only access without the clone
and write-back, and the global `sentry::read_scope` exposes the same
via the active hub, mirroring `sentry::configure_scope`.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Switch pure-read `configure_scope` call sites to the new `read_scope`:
the `sentry-tracing` layer resolves the parent span on every new
tracing span, so this avoids cloning the entire scope and writing it
back on that hot path. Also update the performance-demo example to
demonstrate the new API.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@bardiharborow bardiharborow requested a review from a team as a code owner July 10, 2026 08:57
@szokeasaurusrex

szokeasaurusrex commented Jul 10, 2026

Copy link
Copy Markdown
Member

Hi @bardiharborow, thanks for the PR.

Seems like an interesting and potentially useful proposal, but it could take some time before we can give this a proper review.

In the meantime, I would appreciate if you can open an issue linked to this PR, where you explain the concrete problem you were experiencing. I understand that the current solution can be wasteful on hot paths, but it would be helpful to know where you noticed this, and how much improvement these proposed changes generated.

Additionally, it would be super helpful if you can also document any other alternative approaches you considered. I see that you made the commits with Claude, so if you could export the entire Claude session (or a summary of it) and attach it to the issue, that would be very much appreciated. 🙏 That will help us to provide a better, and likely quicker, review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants