feat(core): Add read_scope for read-only scope access#1235
feat(core): Add read_scope for read-only scope access#1235bardiharborow wants to merge 2 commits into
read_scope for read-only scope access#1235Conversation
`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>
|
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. |
Hub::configure_scopeclones 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_scopewhich provides read-only access without the clone and write-back, and the globalsentry::read_scopeexposes the same via the active hub, mirroringsentry::configure_scope. It also switches existing call sites where appropriate.