getsentry / sentry-javascript

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

@sentry/next.js v 7.23.1 stops sending events #6475

Closed isaac-martin closed 1 year ago

isaac-martin commented 1 year ago

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/nextjs

SDK Version

7.23.0

Framework Version

7.23.0

Link to Sentry event

No response

Steps to Reproduce

After upgrading sentry to @sentry/next js to 7.23.1 we no longer get events sent.

this PR i believe is the culprit https://github.com/getsentry/sentry-javascript/pull/6267 and looking at the code and the description that makes sense.

Our configs are below, and im wndering if its something in the ts-node register that is causing next to exclude the withSentryConfig from the bundle.

I also tried with just the sentry plugin and not using the next-compose-plugins and still was not able to send events

next.config.ts looks like the below

import NextBundleAnalyzer from "@next/bundle-analyzer";
import { withSentryConfig } from "@sentry/nextjs";
import { NextConfig } from "next";
import withPlugins from "next-compose-plugins";

import envVariables from "@brexhq/shared/utils/env/envVariables";
import { isDev } from "@brexhq/shared/utils/env/isDevEnv";

import { ensureEnvVariable } from "./src/utils/dataFetching/env";
import { getSanityToken } from "./src/utils/dataFetching/fetchFromSanity";

const nextConfig: NextConfig = {
  reactStrictMode: true,
  experimental: {
    externalDir: true,
  },
  sentry: {
    hideSourceMaps: true,
  },
  env: {
   ...
  },
  async headers() {
    return [...],
      },
    ];
  },
  async rewrites() {
    return [...];
  },
};

const sentryWebpackPluginOptions = {
  silent: true,
};

const bundleAnalyzer = process.env.ANALYZE
  ? NextBundleAnalyzer({
      enabled: process.env.ANALYZE === "true",
    })
  : (config: any) => config;

const sentry = withSentryConfig(nextConfig as any, sentryWebpackPluginOptions);

const images = {
  images: {
    remotePatterns: [
      {
        protocol: "https",
        hostname: "brand.brex.com",
        pathname: "/**",
        port: "",
      },
    ],
  },
};

module.exports = withPlugins([sentry, bundleAnalyzer, images]);

next.config.js is this which compiles the next.config.ts

require("ts-node").register({
  compilerOptions: {
    module: "commonjs",
    target: "es2017",
  },
});

require("tsconfig-paths/register");

module.exports = require("./next.config.ts");

Expected Result

Sentry sends events

Actual Result

No events are sent via sentry, and I observe no network calls being made.

lforst commented 1 year ago

Hi, is this just affecting next dev or also next build && next start? Also, the newer versions of the SDK are most likely not compatible with next-compose-plugins, since that package doesn't respect the fact that next configurations can return functions (which withSentryConfig does out of necessity).

Edit: Some subjective and unasked-for opinions. Looking at next-compose-plugins, I really recommend not using it anymore. It got updated last two years ago and it's only a matter of time until it causes more problems.

isaac-martin commented 1 year ago

Yeah i actually found this issue and was able to solve based on the content in here.

https://github.com/getsentry/sentry-javascript/issues/6447

Thanks for the response