Skip to content
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

Source map getting uploaded on sentry but not applying to errors #8772

Closed
3 tasks done
gauravsapkal1 opened this issue Aug 9, 2023 · 12 comments
Closed
3 tasks done

Comments

@gauravsapkal1
Copy link

gauravsapkal1 commented Aug 9, 2023

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/browser

SDK Version

7.61.0

Framework Version

next 11.1.3

Link to Sentry event

https://...-ai-3o.sentry.io/issues/4383028081/?project=4505550350516224&query=is%3Aunresolved&referrer=issue-stream&stream_index=2

SDK Setup

in app.js i am doing this
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
integrations: [
new BrowserTracing()
],
tracesSampleRate: 0.2,
});

In sentry.client.config.js
import * as Sentry from "@sentry/nextjs";
import { ContextLines } from "@sentry/integrations";

Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
tracesSampleRate: 0.2,
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 0.1,
release: process.env.NEXT_PUBLIC_SENTRY_PROJECT_NAME,
integrations: [
new Sentry.Replay(),
new ContextLines({
frameContextLines: 7,
}),
],
});

In next.config.js
const { withSentryConfig } = require("@sentry/nextjs");

const nextConfig = {
.. nextjs configurations
productionBrowserSourceMaps: true,
};

const sentryWebpackPluginOptions = {
org: process.env.NEXT_PUBLIC_SENTRY_ORG_NAME,
project: process.env.NEXT_PUBLIC_SENTRY_PROJECT_NAME,
authToken: process.env.NEXT_PUBLIC_SENTRY_AUTH_TOKEN,
// silent: true,
};

const sentryOptions = {
widenClientFileUpload: true,
transpileClientSDK: true,
disableLogger: true,
disableServerWebpackPlugin: true,
disableClientWebpackPlugin: true,
};
module.exports = withSentryConfig(nextConfig, sentryWebpackPluginOptions, sentryOptions);

sentrysourcemap.js
const SentryCli = require('@sentry/cli');

async function uploadSourcemapsAndRelease() {
const release = "...-error-tracking";
if (!release) {
return;
}
const cli = new SentryCli();
try {
console.log('Creating sentry release ' + release);
// creates a new release, in our case its 1.3
await cli.releases.new(release);

// uploads already generated source maps by CRA to sentry
await cli.releases.uploadSourceMaps(release, {
  include: ['.next/'],
  urlPrefix: '~/static/',
  rewrite: false,
});
await cli.releases.finalize(release);

} catch (e) {
console.error('uploading failed:', e);
}
}
uploadSourcemapsAndRelease();

I am running sentrysourcemap.js file after build so that sourcemap will get uploaded after build process of next.js willl completed.

also i added .sentryclirc file and added
[defaults]
project=project name
org=org name

[auth]
token=auth token

So by this code souce map getting uploaded in sentry but they are not getting tracked properly and giving error as "We've encountered 1 problem un-minifying your applications source code!
Source Maps not uploaded

Read Guide
It looks like you're creating, but not uploading your source maps. Read our docs for troubleshooting help."

Steps to Reproduce

I added sentry browsertracing in app.js so after getting error event is getting trigered but not showing proper starce on sentry dashboard, i added images of sourcemap getting uploaded and error showing
Screenshot 2023-08-09 at 8 02 36 PM
Screenshot 2023-08-09 at 8 03 36 PM
Screenshot 2023-08-09 at 8 04 08 PM

Expected Result

stack starce should be shown with proper js path and code

Actual Result

stack strace not showing giving error as sourcemap not detected

@gauravsapkal1
Copy link
Author

@lforst please guide me

@lforst
Copy link
Member

lforst commented Aug 10, 2023

You're doing a lot of custom things that are extremely error-prone. Please follow the guide here or even better, delete your custom logic and run the wizard:

npx @sentry/wizard@latest -i nextjs

If that doesn't work, feel free to write again. Note that we can more quickly help you out if you properly format your issue and explain why you're doing stuff the way you're doing it.

As for:

@lforst please guide me

We'd appreciate it if people don't write comments like these. We already get notifications for every new issue. No need to ping individuals.

@NestlyS
Copy link

NestlyS commented Sep 11, 2023

Hi!

I have similar problem. I googled whole internet, but still couldn't find any solution.

I am using "@sentry/webpack-plugin": "^2.7.0",
I have launched @sentry/wizard@latest for webpack several times, but still have no effect.
Also I am using self-hosted sentry.

My webpack-razzle config:

const { sentryWebpackPlugin } = require('@sentry/webpack-plugin');

module.exports = {
  devtool: 'source-map',
  plugins: [
    <another plugins>
  ],
  modifyWebpackConfig: ({
    env: { target, dev: isDev },
    webpackConfig,
    options: { razzleOptions },
  }) =>
    (async () => {
      const appConfig = { ...webpackConfig };

      if (!isDev) {
        console.log(Object.entries(process.env));

        appConfig.plugins.push(
          sentryWebpackPlugin({
            release: {
              name: process.env.SENTRY_RELEASE,
            },
            sourcemaps: {
              // Specify the directory containing build artifacts
              assets: ['./build/server.js.map', './build/server.js', './build/public/static/js/**'],
              // Don't upload the source maps of dependencies
              ignore: ['./node_modules/**'],
            },
            org: process.env.SENTRY_ORG,
            project: process.env.SENTRY_PROJECT,
            authToken: process.env.SENTRY_AUTH_TOKEN,
            url: process.env.SENTRY_URL,
            debug: true,
            errorHandler: err => {
              console.warn(`!!!SENTRY ERROR: ${err}!!!`);
            },
          }),
        );
      }

So, the only thing I've added is release, because release is declared in upper scope, and route to sourcemaps. However, I still have only artefact bundles, but no release bundles. So sentry tells me, that my sourcemaps are not loaded.

The last thing is I noticed, that my sourcemaps were loaded like artifact bundle.

Screen of an artifacts bundles:
image

But there is no release artifacts:
image

So sentry can't unminify it:
image

In local build it says, that I have an artifact build:
Без названия

Pls, help

@lforst
Copy link
Member

lforst commented Sep 13, 2023

@NestlyS
Copy link

NestlyS commented Sep 18, 2023

@lforst , yes, i did.
I'm sorry to be late with the reply.

I've got some logs, so here are the screenshots:

Use the CLI

The result of using the sentry-cli function:

image

Verify Artifacts Are Uploaded

Yeap, they are uploaded in artifact bundles:
image

But there is nothing in release bundles:
image

Verify Your Source Files Contain Debug ID Injection Snippets

image

Verify your source maps work locally

image

The remaining problems absolutely are not suitable for my case.

However all of problems are related to errors in loading artifacts, but not with the problem when Sentry is unable to actually connect artifact bundles with the release.

@lforst
Copy link
Member

lforst commented Sep 18, 2023

@NestlyS Do the events in sentry have a debug_meta property in the json payload?

Also, are you on self-hosted or SaaS? If you are on saas can you share a link to the event? Thanks!

@NestlyS
Copy link

NestlyS commented Sep 18, 2023

@lforst , nope, I don't have any debug_meta or I don't know where is it.

That is payload in browser
image

I noticed that I have an old version of the SDK. I will try to update it.

And I have an self-hosted version of Sentry.

UPD

After updating the SDK I finally found debug_meta.
Here's an example from my payload

"debug_meta":{"images":[{"type":"sourcemap","code_file":"https://<host>/rnews/static/js/bundle.desktop.9a9bb001.js","debug_id":"3c4451d8-81d4-49ce-83bf-73f774031101"}

@lforst
Copy link
Member

lforst commented Sep 19, 2023

@NestlyS cool that you figured out that you had to upgrade your SDK. When you build your app and upload the resulting build artifacts (that contain the debug IDs) to Sentry, you should now see source maps!

@getsantry
Copy link

getsantry bot commented Oct 10, 2023

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 remove the label Waiting for: Community, I will leave it alone ... forever!


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

@getsantry getsantry bot added the Stale label Oct 10, 2023
@NestlyS
Copy link

NestlyS commented Oct 10, 2023

Sorry for being silent.

I finally solved my problem: it was on self-hosted sentry side so the Sentry application couldn't find the source maps for a specific release. Sentry version update and npm packages update both helped.

Thank you!

@Hariprakash010501
Copy link

@NestlyS , Could you please elaborate what are the npm packages need to be updated?

@lforst
Copy link
Member

lforst commented Jan 29, 2024

@Hariprakash010501 likely all the packages starting with @sentry/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

5 participants