Skip to content

captureException() creates an issue, logged with one event ID, but returns a non-existent event ID. #6229

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

Closed
3 tasks done
FxllenCode opened this issue Nov 17, 2022 · 10 comments

Comments

@FxllenCode
Copy link

FxllenCode commented Nov 17, 2022

Is there an existing issue for this?

How do you use Sentry?

SaaS/Paid Plan

Which package are you using?

@sentry/node

SDK Version

7.20.0

Framework Version

No response

Link to Sentry event

https://sentry.io/organizations/status-plus/issues/3573587519/events/88bf7d9ee40946ff8d9755980849758a/events/?project=6159258

Steps to Reproduce

  1. Had an error in which we capture it as below:
const Sentry = require('../../utils/logging/sentry.js')
const webhook = require('../../utils/webhook.js')

module.exports = {
  config: {},
  event: async (_, id) => {
    console.log(`Shard #${id} ready`)
    await webhook.proxySend(process.env.aliveWebhook, {
      content: `Shard #${id} ready`,
    })
    process.on('unhandledRejection', async (error) => {
      console.log('unhandledRejection', error.message);
      const issue_id = Sentry.captureException(error, {
        tags: {
          shard: id,
        },
      })
      await webhook.proxySend(process.env.deadWebhook, {
        content: `Code-Error occured on shard #${id} \n \n More information available on Sentry with code: \`${issue_id}\`!`,
      })
    });
  },
}
  1. Send the event to Sentry, and send the issue.idto the user.
  2. See the event ID logged in the program.
  3. Open Sentry.io
  4. Search for events with that ID
  5. No events are found
  6. Look at other issues
  7. Find an issue created with the exact parameters of the issue in our program, but the event IDs do not match.

Expected Result

image

When we go to Sentry,io and search for events, we should find an event with this hash.

image

Actual Result

There is no event with the event ID given to the user. Furthermore, an issue is created, but the event IDs do not match up:

image

image

image

@FxllenCode
Copy link
Author

FWIW, we have another issue with transactions that may be related. Writing the issue for that right now.

@Lms24
Copy link
Member

Lms24 commented Nov 18, 2022

Hi @FxllenCode thanks for writing in!
I see you're capturing the exception with Sentry in your onunhandledRejection handler. Does this mismatch in ids only occur in this situation? Our SDK also instruments the process.onunhandledRejection so I'm wondering if there's some sort of collision going on.

You could try disabling our OnUnhandledRejection integration like so:

Sentry.init({
  // ...
  integrations: (integrations) => {
    return integrations.filter(i => i.name !== 'OnUnhandledRejection')
  }
});

Let me know if this helps

@FxllenCode
Copy link
Author

Hi @Lms24!

Thanks for the quick response!

Does this mismatch in ids only occur in this situation?

To my knowledge, it only happens in that situation.

Disabling the integration is a workaround, but we still want to send other events that are unhandled to Sentry, so it does not work for our usecase.

@lobsterkatie
Copy link
Member

lobsterkatie commented Nov 18, 2022

Hi, @FxllenCode.

In your screenshots, it's the the events tab within an issue, correct? Can you please try the same id:xxx search on the main Issue Stream page? It's a long shot, but maybe it's not getting grouped correctly. That said, it's definitely possible that the double-handler thing is the cause, and one of the events is getting deduped.

It looks like you're implementing your own handler just so you can get the event id and post to the webhook. Is that true? If so, a better solution would be to add an event processor which does the same thing:

Sentry.init(...);

Sentry.addGlobalEventProcessor(event => {
  // read id off of event object
  // post to webhook
  return event;
});

Can you please try that and let us know what happens?

@FxllenCode
Copy link
Author

In your screenshots, it's the the events tab within an issue, correct? Can you please try the same id:xxx search on the main Issue Stream page? It's a long shot, but maybe it's not getting grouped correctly. That said, it's definitely possible that the double-handler thing is the cause, and one of the events is getting deduped.

That did not resolve the issue in our case, thanks for trying though!

It looks like you're implementing your own handler just so you can get the event id and post to the webhook. Is that true? If so, a better solution would be to add an event processor which does the same thing:

Is this documented anywhere? This seems nice - but might not be in our niche usecase. I've brought it up with our other team members to take a look at it. Would be nice if the feature worked as intended however!

@lobsterkatie
Copy link
Member

If the event processor doesn't work, you could try turning off the Dedupe integration the same way Lukas showed above, to see if that's actually what's causing the issue.

Event processors are documented here: https://docs.sentry.io/platforms/javascript/enriching-events/event-processors/. (The code for setting a global event processor is slightly different, but it works the same way.)

Also, heads up: I forgot a very important line in my snippet above. You have to return the event or it won't go through! Sorry 'bout that. I've updated it to fix that.

@github-actions
Copy link
Contributor

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@ADTC
Copy link

ADTC commented May 20, 2024

Uh, you require the event ID now in Sentry.showReportDialog, making it mandatory, but when I get the event ID like this const eventId = Sentry.captureException(error) it's a non-existent event ID.

How do I get the correct event ID? Why is this issue closed without fixing? This is a critical issue.

See also: #1940

@Kobby-Bawuah
Copy link

Hey @Lms24 and @lobsterkatie,

@ADTC reached out to us in regards to the different event IDs. Could I get a word on how the user could resolve or get around this issue?

@Lms24
Copy link
Member

Lms24 commented May 23, 2024

Hey @ADTC,

Since version 8.1.0 of the SDK, eventId is no longer required on showReportDialog. If it's not provided, the SDK will set the event id provided from lastEventId().

It's important to note though that regardless of getting the id by calling Sentry.lastEventId() or the returned id from APIs like captureException, there's no guarantee that the id ends up in Sentry. A lot of things can happen in between:

  • the error event is filtered on the SDK side (e.g. beforeSend, ignoreErrors, it's deduplicated, etc)
  • the SDK can't send the error event (too many other events waiting to be sent, network errors, etc)
  • the Sentry backend drops the error (for example due to inbound filters) or in rare cases changes the id.

The underlying reason for this is that the SDK does not await the response of our backend ingestion service Relay when sending requests with the events to get back the "final" eventId. Instead it generates the id of the event right at the beginning and this is the Id you get back through the APIs mentioned above. Usually, if the event is not dropped along the way, this will be the id that ends up in Sentry. However, as you can see here, it's not always the case.

You can listen to a mostly internal SDK event that fires after the event was sent to Sentry. This should rule out cases where the event is getting dropped from the SDK. However, Relay or our backend in general could still filter out the event.

Sentry.getCurrentScope().getClient()?.on("afterSendEvent", (event) => {
  if (!event.type) { // only show the dialog for error events
    Sentry.showReportDialog({ eventId: event.event_id });
  }
});

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

No branches or pull requests

5 participants