feat: add scope context API - #1371
Conversation
0bb8a70 to
8ce983c
Compare
8ce983c to
3ce9717
Compare
| } | ||
|
|
||
| // WithScope is a shorthand for CurrentHub().WithScope. | ||
| func WithScope(f func(scope *Scope)) { |
There was a problem hiding this comment.
why are only these methods removed here and not the others? can you add a short summary of the breaking changes in the PR description?
There was a problem hiding this comment.
+1, please also adjust the PR title to feat! so that Craft identifies this as a breaking change
There was a problem hiding this comment.
Didn't remove the rest because of test usage. Functionality of the scope propagation on ctx isn't finalized on this PR so can't really swap, but it's a fair argument. I'll re-add this and remove everything with all Hub functionality on the final PR to only have public API breaking changes under a single part of the stack.
szokeasaurusrex
left a comment
There was a problem hiding this comment.
lgtm! Left a few minor comments and a question
| boundClient: scope.boundClient, | ||
| eventProcessors: scope.eventProcessors[:len(scope.eventProcessors):len(scope.eventProcessors)], | ||
| scopeData: data.clone(), |
There was a problem hiding this comment.
[question] does the reordering of scopeData after eventProcessors change the code's behavior? Or is it simply a formatting change?
I am just trying to understand why this change is being made here.
There was a problem hiding this comment.
Doesn't affect code behavior. This diff is just adding scope.boundClient.
| // Clearing or cloning the scope only affects the underlying data. To set a new | ||
| // client or event processor, SetClient or AddEventProcessor should be used. |
There was a problem hiding this comment.
l: I find this paragraph to be slightly unclear. What is meant by the "underlying data" in this context?
There was a problem hiding this comment.
It's everything under scopeData, which is essentially all the data set by the user. Not really sure how to call this.
| } | ||
|
|
||
| // WithScope is a shorthand for CurrentHub().WithScope. | ||
| func WithScope(f func(scope *Scope)) { |
There was a problem hiding this comment.
+1, please also adjust the PR title to feat! so that Craft identifies this as a breaking change
3ce9717 to
24cbd32
Compare
1ba25e1 to
5ebf737
Compare
5ebf737 to
14a0bf8
Compare
14a0bf8 to
01f70b4
Compare
01f70b4 to
a32c046
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a32c046. Configure here.
a32c046 to
7c286e0
Compare
7c286e0 to
e747b11
Compare
| func (scope *Scope) SetClient(client *Client) { | ||
| scope.mu.Lock() | ||
| defer scope.mu.Unlock() | ||
|
|
||
| scope.clientOverride = normalizeClient(client) | ||
| } |
There was a problem hiding this comment.
Bug: The SetClient documentation says passing nil clears the override, but the implementation sets a non-nil NoopClient, violating the API contract.
Severity: LOW
Suggested Fix
Either update the documentation to reflect the actual behavior, change the implementation to store nil when nil is passed, or create an explicit ClearClient() method instead of using SetClient(nil).
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: scope.go#L105-L110
Potential issue: The documentation for the `SetClient` function at `scope.go:103-104`
states that passing `nil` will clear the client override. However, the implementation at
line 109 calls `normalizeClient(client)`, which returns a non-nil `NoopClient` when the
input is `nil`. This results in `scope.clientOverride` never being set to `nil`. While
the runtime behavior correctly falls back to the global scope due to subsequent
`IsEnabled()` checks, this discrepancy violates the documented API contract and the
principle of least surprise for developers expecting the override to be `nil`.

Description
Issues
context.Context#1367Changelog Entry Instructions
To add a custom changelog entry, uncomment the section above. Supports:
For more details: custom changelog entries
Reminders
feat:,fix:,ref:,meta:)