Skip to content

Sentry.captureException returns undefined event id due to data racing #6380

@haritowa

Description

@haritowa

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/node

SDK Version

7.23.0

Framework Version

v18.9.0

Link to Sentry event

No response

Steps to Reproduce

  1. Record an exception via Sentry.captureException
  2. Observe return result (00000000....)

The problem is with baseclient.js:96

/**
   * @inheritDoc
   */
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
   captureException(exception, hint, scope) {
    // ensure we haven't captured this very object before
    if (utils.checkOrSetAlreadyCaught(exception)) {
      (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log(ALREADY_SEEN_ERROR);
      return;
    }

    let eventId;
    this._process(
      this.eventFromException(exception, hint)
        .then(event => this._captureEvent(event, hint, scope))
        .then(result => {
          eventId = result; <===== it runs second after function exits.
        }),
    );

    return eventId; <===== It runs first. And this value is used in hub.js captureException
  }

Expected Result

Event ID

Actual Result

Undefined which is mapped to 000000...

Metadata

Metadata

Assignees

Labels

Package: coreIssues related to the Sentry Core SDK

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions