getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.87k stars 1.55k forks source link

All Errors Being Marked as Third Party in NextJS with thirdPartyErrorFilteringIntegration enabled #13286

Open kerenkhatiwada opened 1 month ago

kerenkhatiwada commented 1 month ago

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

8.24.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

After configuring the thirdPartyErrorFilterIntegration to apply a tag to issues if they contain third-party stack frames, issues are incorrectly tagged as being from a third party.

  1. Add applicationKey to next.config.js and add the thirdPartyErrorFilterIntegration to Sentry.init() next.config.js

    
    export default withSentryConfig(nextConfig, {
    
    applicationKey: "SentryKeyWithoutThirdParty",

});

Sentry.client.config.js

Sentry.init({

integrations: [

Sentry.thirdPartyErrorFilterIntegration({
  filterKeys: ["SentryKeyWithoutThirdParty"],
  behaviour: "apply-tag-if-contains-third-party-frames",

}),

],

});


2. build and run the Next.js app
3. observe issues, always have the third_party_code tag set as true

https://org2-w7.sentry.io/issues/5615320176/events/33b552bfbbd8422db76734d93203f883/
https://org2-w7.sentry.io/settings/projects/nextjs14/source-maps/artifact-bundles/ff407422-2b74-5662-84b7-a70ebdde9fd3/?query=306f2601-113c-4fb2-9666-d8fe6b89d8e3
same result with `behaviour: "apply-tag-if-exclusively-contains-third-party-frames"`

Additional info:
window._sentryModuleMetadata is undefined:
![Image](https://github.com/user-attachments/assets/6a3180fc-0d6c-48b9-abe5-7b04a9c42d76)

When behaviour is set to behaviour: "drop-error-if-contains-third-party-frames" events are dropped:
![Image](https://github.com/user-attachments/assets/73935f59-2fa5-49fb-bf29-cff524c852c5)

### Expected Result

third_party_code tag is set to False or not at all for errors occurring in my app

### Actual Result

third_party_code tag is set as True for errors occurring in my app
lforst commented 1 month ago

Hi, withSentryConfig doesn't have a applicationKey option yet. You need to set it as follows: https://github.com/getsentry/sentry-docs/blob/20f3e453407d74335b90bfdccd7a845ef8c69a4f/apps/changelog/next.config.mjs#L53-L56 (this is how we do it in our own changelog)

export default withSentryConfig(nextConfig, {
  unstable_sentryWebpackPluginOptions: {
    applicationKey: 'sentry-changelog',
  },
});