getsentry / sentry-javascript

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

Microfrontends with module federation doesn't have frame.module_metadata.dsn when transport error with beforeSend #14156

Open tweety18 opened 12 hours ago

tweety18 commented 12 hours ago

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/angular

SDK Version

"@sentry/angular": "8.35.0" and "@angular-architects/module-federation": "^17.0.8"

Framework Version

"@sentry/angular": "8.35.0"

Link to Sentry event

can't provide, there is private repo

Reproduction Example/SDK Setup

As you mention in documentation, Sentry inits only once in core application. Sentry.init({ //ufo-core project dsn: environment.dsn, tracesSampleRate: 1.0, sampleRate: 1.0, environment: environment.name, sendDefaultPii: false, integrations: [ Sentry.browserTracingIntegration({}), Sentry.captureConsoleIntegration({levels: ['error']}), Sentry.extraErrorDataIntegration(), Sentry.httpClientIntegration({ failedRequestStatusCodes: [400, 599], }), Sentry.moduleMetadataIntegration() ], transport, beforeSend: (event) => { if (event?.exception?.values?.[0].stacktrace?.frames) { const frames = event.exception.values[0].stacktrace.frames; // Find the last frame with module metadata containing a DSN const routeTo = frames .filter( (frame) => frame.module_metadata && frame.module_metadata.dsn, ) .map((v) => v.module_metadata) .slice(-1);

        if (routeTo.length || window.history.state.dsn) {
            event.extra = {
                ...event.extra,
                [EXTRA_KEY]: routeTo.length ? routeTo :
                [{
                    dsn: window.history.state.dsn,
                    release: event.release
                }],
            };
        }
    }
    return event;
}

})

In microfrontend with module federation I use this configs: module.exports = merge(baseConfig, { devtool: "source-map", plugins: [ SentryWebpackPlugin({ moduleMetadata: ({ release }) => ({ dsn: "dsn_path", release,

        }),
        org: process.env.SENTRY_ORG,
        project: process.env.SENTRY_PROJECT,
        authToken: process.env.SENTRY_AUTH_TOKEN,
    })
],

});

Also, sentry dependency doesn't share in core app for other microfrontends. When http error occurs interceptor in core app call Sentry.captureException(new Error(errorResponse.message))

Steps to Reproduce

  1. init sentry in core app with mentioned below config
  2. in microfrontend with module federation add config to webpack config as mentioned below
  3. reproduce http error with status code 400-599
  4. such error type get caught by common project because for some reason this condition "frame.module_metadata && frame.module_metadata.dsn" isn't true. However, when another error occurs (for example, method with throw error) it transport error to specific project as expected

Expected Result

transport http errors, which appoint in microfrontend with module federation, from core app by beforeSend to specific project

Actual Result

only http errors which appoint in microfrontend with module federation get caught by common project and can't transport by beforeSend because of false value of this condition "frame.module_metadata && frame.module_metadata.dsn"

AbhiPrasad commented 9 hours ago

Hi @tweety18. Because of the varied nature of microfrontend setups, could you help us dig deeper into this by sharing an example reproduction? That will allow us to debug this faster. Thanks!