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

Sentry source maps completely incorrect and showing sentry debug stuff? #575

Open
OultimoCoder opened this issue Jul 21, 2024 · 16 comments
Open

Comments

@OultimoCoder
Copy link

OultimoCoder commented Jul 21, 2024

Image

    "@sentry/esbuild-plugin": "^2.21.1",
    "toucan-js": "3.1.0",
try {
  await build({
      entryPoints: ['./src/index.ts'],
      bundle: true,
      outdir: './dist/',
      sourcemap: true,
      minify: true,
      conditions: ['worker', 'browser'],
      outExtension: { '.js': '.mjs' },
      format: 'esm',
      target: 'esnext',
      plugins: [
        sentryEsbuildPlugin({
          authToken: process.env.SENTRY_AUTH_TOKEN,
          org: 'orf',
          project: 'project',
          include: './dist',
          disable: process.env.ENV !== 'production'
        })
      ]
    })
} catch(err) {
  process.exitCode = 1
}
> Found 2 files
> Analyzing 2 sources
> Analyzing completed in 0.004s
> Adding source map references
> Bundling completed in 0.125s
> Bundled 2 files for upload
> Bundle ID: f17b8fd9-470e-5961-afe1-00f7ea82314d
> Optimizing completed in 0.006s
> Uploading completed in 1.267s
> Uploaded files to Sentry
> Processing completed in 0.192s
> File upload complete (processing pending on server)
> Organization: org
> Project: project
> Release: 6e009e82d6b4e59d4e4859ac732b6e18bc3415c8
> Dist: None
> Upload type: artifact bundle

Source Map Upload Report
  Scripts
    ~/6a54addc-dff9-48a1-b200-ec525a558630-0.js (sourcemap at index.mjs.map, debug id 6a54addc-dff9-48a1-b200-ec525a558630)
  Source Maps
    ~/6a54addc-dff9-48a1-b200-ec525a558630-0.js.map (debug id 6a54addc-dff9-48a1-b200-ec525a558630)
[sentry-esbuild-plugin] Info: Successfully uploaded source maps to Sentry
@s1gr1d
Copy link
Member

s1gr1d commented Jul 22, 2024

Hello, thanks for writing. Seeing Sentry debug code should not be the case. Do you maybe use other plugins that modify your sourcemaps? And it would be great to get a small reproduction example from you, so we can look into this.

@aleesaan
Copy link

Hey @s1gr1d I'm also having the same issue, which seems to be related to #471, as in the source maps I'm getting for example:

import "_sentry-debug-id-injection-stub";
import * as aModule from "/path/to/file.js";
export default aModule.default;
export * from "/path/to/file.js";

Which raises the import-is-undefined warning.

I tried to remove all plugins and use the simplest possible config, but the only way to fix the esbuild's source maps is not using sentry, which is kind of the reason I need source maps in the first place 😅 I don't quite get how other people are using this esbuild plugin, maybe it broke recently?

@lforst
Copy link
Member

lforst commented Jul 26, 2024

@aleesaan would you mind sharing your code or a minimal reproduction? It would help us debug this issue effectively.

@aleesaan
Copy link

aleesaan commented Jul 26, 2024

Hey @lforst I created a small repro on stackblitz but it's probably best to try this locally to also run the app and check the source maps in the browser.

Here it is: https://stackblitz.com/edit/esbuild-95tv8h?file=build.mjs

You can see the compilation is giving the import-is-undefined warning as I mentioned, and the source maps in the dist folder include a _sentry-debug-id-injection-stub.

@aleesaan
Copy link

Hey @lforst I just looked more into it and it seems like we get this _sentry-debug-id-injection-stub when using sourcemap: true, which I use during development for example; in that case the source maps in the browser don't work. When using sourcemap: 'external' we still get the import-is-undefined warning, but the source maps do work on sentry, I tested it in my project and when throwing an error I do see the stack trace in the sentry exception.

@lforst
Copy link
Member

lforst commented Jul 26, 2024

@aleesaan thanks for the repro! The source maps from your reproduction generally look fine to me. The content of the source maps may look weird but the source mapping should properly work 🤔

The "import-is-undefined" warning we cannot fix at the moment and is tracked in #471 which you already found.

Do you happen to have an error and repro where the source mapping doesn't work?

Also: We generally don't optimize the bundler plugins for development, and only for production builds. Any of their functionality may not work in dev servers.

@aleesaan
Copy link

@lforst you're right, I thought sourcemap: true was creating the issue, but I tried again in the repro I shared and it doesn't seem like that's the case. I've been trying to reproduce this issue in the clean repo but I can't, even though the same exact config break the source maps in my actual project, classic! 😅 Breaks in the sense that they look like the snippet I shared earlier, rather than actual source maps.

@aleesaan
Copy link

FWIW here's an example config that's failing for me in my project:

{
  sourcemap: true,
  entryPoints: [
    ...
  ],
  bundle: true,
  logLevel: 'info',
  target: ['es2022'],
  outdir: 'path/to/dist',
  define: {
    ...
  },
  external: [
    ...
  ],
  plugins: [
    sentryEsbuildPlugin({
      org: "org",
      project: "project",
      url: "url",
      authToken: process.env.SENTRY_AUTH_TOKEN,
      release: {
        name: process.env.RELEASE,
      },
    }),
  ],
}

I was using other plugins but I removed them (to isolate the issue) and it still creates wrong source maps. If I remove sentryEsbuildPlugin I can see the correct source maps in the browser.
What I don't get is why I'm not able to reproduce this issue in the clean repo using this exact setup 😕

@lforst
Copy link
Member

lforst commented Jul 29, 2024

@aleesaan I am still struggling to understand the exact issue at hand 🤔 I think there might be something wrong with our plugin but can't quite put a finger on it (we're admittedly doing some shady shit because esbuild's plugin API is very restricted). Feel free to share more complicated code if it is able to reproduce! It would help a lot.

@aleesaan
Copy link

aleesaan commented Aug 2, 2024

Not sure if that can help anybody but I managed to get my source maps to work by using sourcemap: 'inline' instead of sourcemap: true!

@OultimoCoder
Copy link
Author

OultimoCoder commented Sep 14, 2024

Still completely fucked for me. Every repo I try it in has the same issue. Legit I have one repo and I use a different branch per customer. My own sentry account (free tier) fucked source maps. My customers account, perfect source maps (paid tier). There is 0 difference in build/deployment code other than the paid tier on Sentry lol.

@lforst
Copy link
Member

lforst commented Sep 16, 2024

@OultimoCoder I can confidently say that paid or not paid will not play a role in source mapping. Can you verify that you have the right auth token?

@OultimoCoder
Copy link
Author

100% have the right auth token. This occurs across every esbuild repo I have minus my customer's branch on 1 repo.

In this specific instance. Both are the same repo, same dependencies (different auth token and sentry accounts). I can deploy 1, swap branch deploy the other.

With debug enabled I see both are uploaded successfully. I can also double check Sentry to confirm this.

The only difference is custom customer code unrelated to build or deploy.

One has faulty source maps, one works perfectly.

I even deleted build output between swapping branches so its 100% uploading the correct source maps.

@lforst
Copy link
Member

lforst commented Sep 16, 2024

@OultimoCoder maybe you can isolate out what causes this in a small example, so that we can take a proper look.

@OultimoCoder
Copy link
Author

OultimoCoder commented Oct 2, 2024

I am using cloudflare workers for all my projects. If I give you a cloudflare worker repro, do you mind? It kills me everytime I get a sentry error and its useless lol and I'm too lazy to change provider atm.

@lforst
Copy link
Member

lforst commented Oct 3, 2024

@OultimoCoder something we can run ourselves locally without too much hassle would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for: Community
Development

No branches or pull requests

5 participants