Sentry-javascript: Sentry captureException return wrong/not matched event_id with what logged on server

Created on 7 Mar 2019  路  8Comments  路  Source: getsentry/sentry-javascript

Package + Version

  • [x] @sentry/browser": "^4.6.4"
  • [x] @sentry/core": "4.6.4"
  • [x] @sentry/types": "4.5.3"
  • [x] @sentry/utils": "4.6.4"

Version:

4.6.4

Description

  • We was using Raven.js client and it was working, But when we decided to upgrade to new Sentry official SDK for angular2 @sentry/browser, We noticed strange behavior after Sentry log error by captureException return event_id & Sentry.lastEventId() neither matched nor exists with event_id that logged on Sentry 9.0.0, This happened when pass error to captureException, But i works with captureException and when pass new Error(msg), What i expect is when captureMessage error with stackTrace make Sentry client behave wrong when generate event_id.
- After Sentry captureException 
Sentry.init({
    dsn: 'our_dsn',
    whitelistUrls: [some_pattern],
});

handleError(error) {
    const event_id = Sentry.captureException(error);  // wrong/not matched event_id
    console.log(event_id); // 2a4f76154e1446f8baa4cf5e38ed2d7f
    console.log(Sentry.lastEventId()); // 2a4f76154e1446f8baa4cf5e38ed2d7f
 // But expected & what is logged in server is `96474888a8154c409c0dcbea29d792ad`

 // Raven.captureException(error);   // Np correct & matched event_id
 // Sentry.captureException(new Error(error.stack));   // Np correct & matched event_id, but missing frames, extra info on server..
 // Sentry.captureMessage(error.message);   // Np correct & matched event_id
}
Confirmed In Progress Bug

Most helpful comment

All 8 comments

Sorry for the late reply but I am not able to reproduce this.
Here is an example: https://codesandbox.io/s/jpm71lq17w
If I copy the eventId I can find it in the account.

Closing due to the issue getting out-dated. Feel free to ping me to reopen it if it's still relevant.

@kamilogorek I still get the same problem .
When I use const eventId = Sentry.captureMessage(sentryMessage) to get the return eventId of captureMessage, I find that this eventId is different from the sentry server.

And I check the compliled js file, I find that

BaseClient.prototype.captureEvent = function (event, hint, scope) {
        var _this = this;
        var eventId = hint && hint.event_id;
        this._processing = true;
        this._processEvent(event, hint, scope)
            .then(function (finalEvent) {
            // We need to check for finalEvent in case beforeSend returned null
            eventId = finalEvent && finalEvent.event_id;
            _this._processing = false;
        })
            .catch(function (reason) {
            utils_1.logger.error(reason);
            _this._processing = false;
        });
        return eventId;
    };

_processEvent maybe a promise, but this function return eventId directly.
AND check this out:

Hub.prototype.captureEvent = function (event, hint) {
        var eventId = (this._lastEventId = utils_1.uuid4());
        this._invokeClient('capnureEvent', event, tslib_1.__assign({}, hint, { event_id: eventId }));
        return eventId;
    };

same .

@liyechen can you provide some repro case showcasing this issue?

@kamilogorek
Sorry I don't know what you mean repro case. I posted the compiled js up there so I think the problem is kind of clear.
I mean I got the same issue that the eventId returned from captureMessage is different from the server's eventId.
And I think it's because that there are some issues in the BaseClient and Hub, check their function called captureEvent and you can find the issue.
In the BaseClient.captureEvent, eventId sometimes will be changed in the function _processEvent, it looks like a promise function, but eventId is returned directly after it, so eventId is returned before the _processEvent changed it. I think this is why this issue happens.

Hi.
I just wanted to confirm the issue. While everything works properly for regular exceptions, unhandled rejections are being post-processed: the finalEvent variable is being created based on the original event. The original event's id is being assigned to _lastEventId and returned, but the finalEvent is actually being sent to Sentry.

In my case I use the default configuration but I'm also catching global error and unhandledRejection events to display the error to the user, with ID that is supposed to be used when contacting the tech support. Like this:

        window.addEventListener('error', event => {
            console.error(event.error);
            const errorId = Sentry.lastEventId(); // This works fine :)
            this.props.dispatch(openErrorModal({errorId, isCritical: true}));
        });

        window.addEventListener('unhandledrejection', event => {
            console.error(event);
            const errorId = Sentry.lastEventId(); // THIS RETURNS THE INCORRECT ID :(
            this.props.dispatch(openErrorModal({errorId, isCritical: true}));
        }, true);

I have the same issue with Sentry.captureEvent()

While Sentry.captureMessage( ... ) returns the correct event Id, Sentry.captureEvent( ... ) returns a different event Id.

Was this page helpful?
0 / 5 - 0 ratings