Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Capturing Event with EventHint #940

Open
MatsuoTakuro opened this issue Dec 29, 2024 · 0 comments
Open

Support Capturing Event with EventHint #940

MatsuoTakuro opened this issue Dec 29, 2024 · 0 comments

Comments

@MatsuoTakuro
Copy link

Problem Statement

Currently, the Hub does not expose a public method like:

hub.CaptureEventWithHint(event *Event, hint *EventHint)
// or
hub.CaptureEventWithOriginalError(event *Event, originalError error)

However, In SentryHandler.Handle, we wanna:

  1. Capture slog attributes as part of the event.
  2. Attach an original error in EventHint.OriginalException.

Without the above public method, we are now forced to call either:

  • hub.CaptureException(err) – Loses slog attributes.
  • hub.CaptureEvent(event) – Cannot attach EventHint.OriginalException for the BeforeSend callback func.
    • Our project usually edits an event in the callback func, depending on the underlying error type.

Solution Brainstorm

Introduce a new public method in Hub like this:

func (hub *Hub) CaptureEventWithHint(event *Event, hint *sentry.EventHint) *EventID {
    client, scope := hub.Client(), hub.Scope()
    if client == nil || scope == nil {
        return nil
    }

    // Capture the event with hint
    eventID := client.CaptureEvent(event, hint, scope)

    if eventID != nil {
        hub.mu.Lock()
        hub.lastEventID = *eventID
        hub.mu.Unlock()
    }
    return eventID
}

// or

func (hub *Hub) CaptureEventWithOriginalError(event *Event, err error) *EventID {
    client, scope := hub.Client(), hub.Scope()
    if client == nil || scope == nil {
        return nil
    }

    // Create hint with original error
    var hint *sentry.EventHint
    if err != nil {
        hint = &sentry.EventHint{OriginalException: err}
    }

    // Capture the event with hint
    eventID := client.CaptureEvent(event, hint, scope)

    if eventID != nil {
        hub.mu.Lock()
        hub.lastEventID = *eventID
        hub.mu.Unlock()
    }
    return eventID
}
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 29, 2024
@MatsuoTakuro MatsuoTakuro changed the title Support Capturing Events with Error and EventHint in slog handler. Support Capturing Event with EventHint Dec 29, 2024
@getsantry getsantry bot removed the status in GitHub Issues with 👀 3 Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

2 participants