Skip to content

feat: add scope context API - #1371

Open
giortzisg wants to merge 1 commit into
scopes/scope-datafrom
scopes/scope-storage
Open

feat: add scope context API#1371
giortzisg wants to merge 1 commit into
scopes/scope-datafrom
scopes/scope-storage

Conversation

@giortzisg

@giortzisg giortzisg commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Description

Issues

Changelog Entry Instructions

To add a custom changelog entry, uncomment the section above. Supports:

  • Single entry: just write text
  • Multiple entries: use bullet points
  • Nested bullets: indent 4+ spaces

For more details: custom changelog entries

Reminders

@linear-code

linear-code Bot commented Jul 23, 2026

Copy link
Copy Markdown

GO-154

@giortzisg
giortzisg marked this pull request as ready for review July 23, 2026 08:26
Comment thread scope_context.go Outdated
Comment thread sentry.go
@giortzisg
giortzisg force-pushed the scopes/scope-storage branch from 0bb8a70 to 8ce983c Compare July 23, 2026 08:45
@giortzisg
giortzisg force-pushed the scopes/scope-storage branch from 8ce983c to 3ce9717 Compare July 30, 2026 20:45
Comment thread scope_context.go
Comment thread sentry.go
}

// WithScope is a shorthand for CurrentHub().WithScope.
func WithScope(f func(scope *Scope)) {

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.

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?

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.

+1, please also adjust the PR title to feat! so that Craft identifies this as a breaking change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 szokeasaurusrex 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.

lgtm! Left a few minor comments and a question

Comment thread scope.go Outdated
Comment on lines +309 to +311
boundClient: scope.boundClient,
eventProcessors: scope.eventProcessors[:len(scope.eventProcessors):len(scope.eventProcessors)],
scopeData: data.clone(),

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.

[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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Doesn't affect code behavior. This diff is just adding scope.boundClient.

Comment thread scope.go
Comment on lines +24 to +25
// Clearing or cloning the scope only affects the underlying data. To set a new
// client or event processor, SetClient or AddEventProcessor should be used.

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.

l: I find this paragraph to be slightly unclear. What is meant by the "underlying data" in this context?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's everything under scopeData, which is essentially all the data set by the user. Not really sure how to call this.

Comment thread sentry.go
}

// WithScope is a shorthand for CurrentHub().WithScope.
func WithScope(f func(scope *Scope)) {

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.

+1, please also adjust the PR title to feat! so that Craft identifies this as a breaking change

@giortzisg giortzisg changed the title feat: add scope context API feat!: add scope context API Aug 4, 2026
@giortzisg
giortzisg force-pushed the scopes/scope-storage branch from 3ce9717 to 24cbd32 Compare August 4, 2026 15:02
Comment thread scope_context.go
Comment thread scope_context.go
@giortzisg giortzisg changed the title feat!: add scope context API feat: add scope context API Aug 10, 2026
@giortzisg
giortzisg force-pushed the scopes/scope-storage branch from 1ba25e1 to 5ebf737 Compare August 10, 2026 11:28
Comment thread scope_context.go Outdated
@giortzisg
giortzisg force-pushed the scopes/scope-storage branch from 5ebf737 to 14a0bf8 Compare August 10, 2026 11:36
Comment thread sentry.go
@giortzisg
giortzisg force-pushed the scopes/scope-storage branch from 14a0bf8 to 01f70b4 Compare August 10, 2026 13:23
@giortzisg
giortzisg force-pushed the scopes/scope-storage branch from 01f70b4 to a32c046 Compare August 13, 2026 11:40

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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.

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.

Comment thread scope_context.go
@giortzisg
giortzisg force-pushed the scopes/scope-storage branch from a32c046 to 7c286e0 Compare August 13, 2026 11:48
@giortzisg
giortzisg force-pushed the scopes/scope-storage branch from 7c286e0 to e747b11 Compare August 13, 2026 12:51
Comment thread scope.go
Comment on lines +105 to +110
func (scope *Scope) SetClient(client *Client) {
scope.mu.Lock()
defer scope.mu.Unlock()

scope.clientOverride = normalizeClient(client)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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`.

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.

3 participants