getsentry / sentry-javascript-bundler-plugins

JavaScript Bundler Plugins for Sentry
https://sentry.io
BSD 3-Clause "New" or "Revised" License
141 stars 36 forks source link

`sourcemaps.rewriteSources` doesn’t apply new source value #531

Closed niksy closed 6 months ago

niksy commented 6 months ago

Environment

Steps to Reproduce

  1. Use Sentry Vite plugin
  2. Add option sourcemaps.rewriteSources: (source) => './' + source.replaceAll('../', '')

Expected Result

Source from source map should be translated to value defined in rewriteSources hook, e.g. ../ should be stripped and ./ should be prepended to source path.

Actual Result

Default value is used which is relative path from process.cwd(), but I’m not sure if that’s valid - I’ve tried to change code directly inside default hook but changes are not applied.

I’m also using RewriteFrames integration, but I haven’t seen any changes if it’s removed.

Is this maybe related to self-hosted Sentry? For upload to work I had to use release.uploadLegacySourcemaps option so maybe these changes don’t get applied?

Lms24 commented 6 months ago

Hey @niksy thanks for writing in!

To debug this, would you mind sharing your vite plugin config?

It could be well-related to self-hosted and uploadLegacySourcemaps. Which makes this extra hard to debug 😅 are you able to update to the latest self-hosted version of Sentry? If so, I think the simpler, debug-id based source map upload apporach should work (tagging @lforst to confirm).

niksy commented 6 months ago

To debug this, would you mind sharing your vite plugin config?

Sure, no problem, here it is:

sentryVitePlugin({
  url: "",
  org: "",
  project: "",
  authToken: "",
  sourcemaps: {
    rewriteSources: (source) => "./" + source.replaceAll("../", ""),
  },
  release: {
    name: commitSha,
    uploadLegacySourcemaps: path.resolve(cwd, "ssr-dist"),
  },
});

are you able to update to the latest self-hosted version of Sentry?

I’ll see what I can do, it would be great if this is fixed just with version bump, it looks like our self-hosted instance version is almost 2 years old 😄

niksy commented 6 months ago

Unfortunately, we’re currently unable to easily upgrade our Sentry instance 😞

lforst commented 6 months ago

One question: Did you look at the sources field of the uploaded artifact (in Sentry) or the local file? sourcemaps.rewriteSources only affects the uploaded artifacts.

niksy commented 6 months ago

@lforst I’ve looked in both places, local and I’ve downloaded uploaded artifact - there isn’t any rewrite done for paths.

I suppose this is something that Sentry Vite plugin should be doing?

lforst commented 6 months ago

@niksy okay thank you! I will take a look.

lforst commented 6 months ago

@niksy Hey, I just took another look. I realized you were using uploadLegacySourcemaps to upload the source maps. The upload process that is kicked off when using that option does not consider any options in the sourcemaps field. If you want to transform sourcemaps when using uploadLegacySourcemaps, I recommend looking into the specific options instead.

I think we can do a better job documenting this. Sorry about that.

niksy commented 6 months ago

Okay, thank you for a fast response!