Skip to content

beforeSend: type event_id and timestamp as required #25286

Open

Description

@abrahamguo

Problem Statement

beforeSend receives an ErrorEvent, which inherits event_id?: string and timestamp?: number from Event. But by the time beforeSend runs, both are always set: _processEvent only calls processBeforeSend with the result of prepareEvent, which does

event_id: event.event_id || hint.event_id || uuid4(),
timestamp: event.timestamp || dateTimestampInSeconds(),

So a common beforeSend use, like showing the user the event ID in a "report this error" link, needs a ! or a fallback that can never run.

Solution Brainstorm

Type the beforeSend parameter as ErrorEvent & { event_id: string; timestamp: number } (or a named "prepared event" type), and do the same for beforeSendTransaction. This only narrows a callback parameter, so existing callbacks still type-check, and the return type can stay ErrorEvent | null.

Additional Context

@sentry/core 11.6.0

Priority

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Activity

  1. linear-code commented on Oct 12, 2026

    @linear-code
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Oct 12, 2026
  3. self-assigned this
    on Oct 12, 2026
  4. Lms24 commented on Oct 12, 2026

    @Lms24
    Member

    Hey @abrahamguo thanks for writing in!

    You're right that we can require event_id and timestamp on in the beforeSend callback. Unfortunately, this is an API breaking change for anyone calling options.beforeSend(event). For example, our React Native SDK which wraps the javascript SDK. For the React Native case, we could fix it, but it serves as a good indication that likely someone out there is doing this. I'm, going to backlog this for v12 to make the change then.

    Regarding beforeSendTransaction: This API is scheduled for removal in favour of beforeSendSpan and ignoreSpans. It will be removed in v12.

  5. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Oct 12, 2026
  6. added this to the 12.0.0 milestone on Oct 12, 2026
  7. removed their assignment
    on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions