getsentry / sentry-javascript

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

Source maps not matching due to file renaming in @sentry/nextjs #13730

Closed annielinnik closed 1 week ago

annielinnik commented 1 month ago

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/nextjs

SDK Version

8.30.0

Framework Version

Next 14.2.6

Link to Sentry event

No response

Reproduction Example/SDK Setup

// sentry.client.config.ts
import * as Sentry from "@sentry/nextjs";

Sentry.init({
  dsn: '...',
  debug: true,
  enabled: true,
  environment: process.env.NEXT_PUBLIC_APP_ENV,
});

// sentry.server.config.ts , sentry.edge.config.ts
import * as Sentry from "@sentry/nextjs";

Sentry.init({
  dsn: '...',
  debug: true,
});

Steps to Reproduce

  1. Throw an error from sentry-example-page generated with npx @sentry/wizard@latest -i sourcemaps

  2. Source maps for this event not working:

  3. This is how the artifacts look like:

The way I see it: Sentry renames files, replacing their names with Debug ID and moving them to the root folder; then Sentry tries to find a file in _next/server/* and fails because there's no such file.

My next.config.js:

const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  output: "standalone",
  i18n: {
    locales: ["en"],
    defaultLocale: "en",
  },
  // fix 'fn' not found
  webpack(config, { webpack }) {
    config.resolve.fallback = {
      fs: false,
      dns: false,
      child_process: false,
    };
    config.plugins.push(
      new webpack.DefinePlugin({
        __SENTRY_DEBUG__: false,
        __SENTRY_TRACING__: false,
      })
    );
    return config;
  },

  async redirects() {
    return [];
  },

  async headers() {
    return [
      {
        // Apply these headers to all routes in your application.
        source: "/:any*",
        headers: [
          {
            key: "X-Frame-Options",
            value: "SAMEORIGIN",
          },
        ],
      },
    ];
  },

  experimental: {
    forceSwcTransforms: true,
    instrumentationHook: true,
  },
};

const nextConfigWithSentry = withSentryConfig(nextConfig, {
  authToken: process.env.SENTRY_AUTH_TOKEN,
  org: "sentry",
  project: "...",
  widenClientFileUpload: true,
  transpileClientSDK: true,
  disableLogger: false,
});

module.exports = nextConfigWithSentry;

Expected Result

Files uploaded to Sentry with their original names and paths. Source maps work.

Actual Result

Every file is renamed with format [debug_id].js and [debug_id].js.map and uploaded at root folder.

lforst commented 1 month ago

Hi, the modal tells you "capture a new event to verify the changes". Can you try and do so? Make sure you set "latest" in the dropdown in the error in the top right corner instead of "recommended". Thanks!

K-Jean commented 1 month ago

Hi ! same problem here with nextjs 15rc. Files are uploaded with the [debug_id].js and not with the served filename :

Image

Image

Image

annielinnik commented 1 month ago

@lforst Same with the 'latest' event. This modal suggests to capture new events for months now, every new event has the same issue.

lforst commented 1 month ago

@K-Jean @annielinnik would you mind providing a link to an event where this happens? Thanks!

lforst commented 1 month ago

Oh @annielinnik you're on self hosted. Please check the logs of your symbolicator service.

K-Jean commented 1 month ago

I'm also in self-hosted environnement. We have a lot of errors in the symbolicator service :

symbolicator-1  | 2024-09-19T21:20:38.952866391Z ERROR symbolicator_service::download: Failed to fetch file list error=download timed out after 30s
symbolicator-1  | 2024-09-19T21:20:38.952887451Z ERROR symbolicator_service::download: Failed to fetch file list error=download timed out after 30s
symbolicator-1  | 2024-09-19T21:20:38.952911202Z ERROR symbolicator_service::download: Failed to fetch file list error=download timed out after 30s
symbolicator-1  | 2024-09-19T21:20:38.952931272Z ERROR symbolicator_service::download: Failed to fetch file list error=download timed out after 30s
symbolicator-1  | 2024-09-19T21:20:38.952956083Z ERROR symbolicator_service::download: Failed to fetch file list error=download timed out after 30s
symbolicator-1  | 2024-09-19T21:20:38.952977453Z ERROR symbolicator_service::download: Failed to fetch file list error=download timed out after 30s
symbolicator-1  | 2024-09-19T21:27:08.26203245Z ERROR symbolicator_service::download: Failed to fetch file list error=download timed out after 30s
symbolicator-1  | 2024-09-19T21:27:08.262105062Z ERROR symbolicator_service::download: Failed to fetch file list error=download timed out after 30s
symbolicator-1  | 2024-09-19T21:27:38.263662134Z ERROR symbolicator_service::download: Failed to fetch file list error=download timed out after 30s
symbolicator-1  | 2024-09-19T21:27:38.263724635Z ERROR symbolicator_service::download: Failed to fetch file list error=download timed out after 30s
symbolicator-1  | 2024-09-20T06:17:59.271961773Z ERROR symbolicator_service::caching::memory: Failed to create cache directory: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }
symbolicator-1  | 2024-09-20T06:17:59.272025495Z ERROR symbolicator_service::caching::memory: Failed to create cache directory: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }
symbolicator-1  | 2024-09-20T06:17:59.272045005Z ERROR symbolicator_service::caching::memory: Failed to create cache directory: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }
symbolicator-1  | 2024-09-20T06:17:59.272075666Z ERROR symbolicator_service::caching::cache_error: error=Permission denied (os error 13)
symbolicator-1  | 2024-09-20T07:11:03.761606347Z ERROR symbolicator_service::caching::memory: Failed to create cache directory: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }
symbolicator-1  | 2024-09-20T07:11:03.761651387Z ERROR symbolicator_service::caching::memory: Failed to create cache directory: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }
symbolicator-1  | 2024-09-20T07:11:03.761667268Z ERROR symbolicator_service::caching::memory: Failed to create cache directory: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }
symbolicator-1  | 2024-09-20T07:11:03.761686718Z ERROR symbolicator_service::caching::cache_error: error=Permission denied (os error 13)
lforst commented 1 month ago

Well that looks like the problem. Seems like you need to give the service network access to your Sentry service and also file write permissions.

K-Jean commented 1 month ago

Hello @lforst you point the right direction for me, I fixed the folder rights see this ticket : https://github.com/getsentry/self-hosted/issues/3114

AbhiPrasad commented 1 week ago

Closing this for clean-up. Please re-open if it still applies. Thanks!