Skip to content

feat: add context capture API - #1378

Open
giortzisg wants to merge 1 commit into
scopes/scope-mergefrom
scopes/context-capture
Open

feat: add context capture API#1378
giortzisg wants to merge 1 commit into
scopes/scope-mergefrom
scopes/context-capture

Conversation

@giortzisg

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

@giortzisg
giortzisg marked this pull request as ready for review July 30, 2026 19:04
@giortzisg
giortzisg requested a review from Litarnus July 30, 2026 19:05
Comment thread client.go
Comment thread client.go
Comment on lines +888 to 889
return client.processEvent(client.EventFromException(err, LevelError), hint, scope)
}

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: A recursive call in processEvent when handling a nil event can cause infinite recursion and a stack overflow if a noopClient is used.
Severity: HIGH

Suggested Fix

Revert the logic inside the if event == nil block to call client.CaptureException(err, hint, scope) instead of making a recursive call to processEvent. This avoids the infinite loop by using the original, safe error handling path.

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: client.go#L888-L889

Potential issue: The `processEvent` function handles a `nil` event by creating a
`usageError` and making a recursive call to itself with an event generated by
`client.EventFromException`. However, when a `noopClient` is active (a common case when
Sentry is disabled or in test environments), its implementation of `EventFromException`
returns `nil`. This creates an infinite recursion loop: `processEvent(nil)` calls
`processEvent(EventFromException(...))`, which evaluates back to `processEvent(nil)`.
This will lead to a stack overflow, crashing the application.

Did we get this right? 👍 / 👎 to inform future reviews.

@giortzisg
giortzisg force-pushed the scopes/context-capture branch from efccd51 to c6716f7 Compare July 30, 2026 20:45

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

Reviewed by Cursor Bugbot for commit c6716f7. Configure here.

Comment thread scope.go
return clone
}

// Clear removes data from the scope while retaining event processors.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clone drops scope last event ID

Medium Severity

Scope.Clone copies boundClient and eventProcessors but not lastEventID, even though Clear retains that ID with those same fields. Forks from WithIsolation / PushScope therefore start with an empty last event ID and hide IDs already captured on the parent scope.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c6716f7. Configure here.

Comment thread hub.go
if hint != nil && hint.Context != nil {
ctx = hint.Context
}
eventID := client.CaptureEvent(ctx, event, WithEventHint(hint), withLegacyScope(scope))

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: A call to hub.CaptureEventWithHint with a nil event will cause a panic due to a nil pointer dereference when accessing event.Type without a nil check.
Severity: HIGH

Suggested Fix

Add a nil check for the event parameter before its properties are accessed. The conditional at hub.go:230 should be modified to if event != nil && event.Type != transactionType && eventID != nil { ... } to prevent the panic.

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: hub.go#L228

Potential issue: In `hub.CaptureEventWithHint`, the `event` parameter can be `nil`. New
code was added that accesses `event.Type` after `client.CaptureEvent` is called.
Although `client.CaptureEvent` handles a `nil` event internally, the original `event`
variable in the `hub.CaptureEventWithHint` scope remains `nil`. The subsequent access to
`event.Type` at `hub.go:230` therefore causes a nil pointer dereference, leading to a
panic. A user calling `hub.CaptureEventWithHint(nil, nil)` will trigger this crash.

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.

1 participant