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

Verbose console print from [sentry-vite-plugin] #523

Closed kenn closed 7 months ago

kenn commented 7 months ago

Environment

@sentry/vite-plugin 2.16.1

Steps to Reproduce

  1. Set up a new Remix Vite app with vite.config.ts as follows:
export default defineConfig(({ mode }) => {
  return {
    build: {
      sourcemap: true,
    },
    plugins: [
      remix(),
      tsconfigPaths(),
      sentryVitePlugin({
        org: 'org',
        project: 'project',
        authToken: process.env.SENTRY_AUTH_TOKEN,
        sourcemaps: {
          filesToDeleteAfterUpload: ['./build/**/*.js.map'],
        },
        // telemetry: mode === 'production',
        // debug: mode === 'production',
      }),
    ],
  }
})

Now, starting the dev server by npm run dev prints [sentry-vite-plugin] and there's no way to silence it. It even prints duplicates.

[sentry-vite-plugin] Info: Using environment variables configured in ".env.sentry-build-plugin".
[sentry-vite-plugin] Info: Using environment variables configured in ".env.sentry-build-plugin".
[sentry-vite-plugin] Info: Sending error and performance telemetry data to Sentry. To disable telemetry, set `options.telemetry` to `false`.
[sentry-vite-plugin] Info: Sending error and performance telemetry data to Sentry. To disable telemetry, set `options.telemetry` to `false`.

I can actually silence telemetry by enabling the telemetry: mode === 'production' config as shown above, but there's no way to silence .env.sentry-build-plugin ?

Expected Result

Silence all of those.

$ npm run dev

> dev
> cross-env NODE_ENV=development node --env-file=.env ./server.js

✅ app ready at http://localhost:3000

Actual Result

$ npm run dev

> dev
> cross-env NODE_ENV=development node --env-file=.env ./server.js

[sentry-vite-plugin] Info: Using environment variables configured in ".env.sentry-build-plugin".
[sentry-vite-plugin] Info: Using environment variables configured in ".env.sentry-build-plugin".
[sentry-vite-plugin] Info: Sending error and performance telemetry data to Sentry. To disable telemetry, set `options.telemetry` to `false`.
[sentry-vite-plugin] Info: Sending error and performance telemetry data to Sentry. To disable telemetry, set `options.telemetry` to `false`.
✅ app ready at http://localhost:3000
lforst commented 7 months ago

There is a silent option which you might be looking for.

kenn commented 7 months ago

There is a silent option which you might be looking for.

Thanks! It says suppress all logs, which sounds a bit too aggressive. Does that still prints important logs such as errors? If so that's what I was looking for!

lforst commented 7 months ago

So if something throws, it should still be shown as part of the Node.js stack trace, but it will silence all logs, including error log messages.

You could use the errorHandler option to still log in case something errors out.

lforst commented 7 months ago

We do not intend to add some sort of log level option as of now I should add.

kenn commented 7 months ago

Got it. Now my config looks like this. Thanks!

export default defineConfig(({ mode }) => {
  return {
    build: {
      sourcemap: true,
    },
    plugins: [
      remix(),
      tsconfigPaths(),
      sentryVitePlugin({
        org: 'org',
        project: 'project',
        authToken: process.env.SENTRY_AUTH_TOKEN,
        sourcemaps: {
          filesToDeleteAfterUpload: ['./build/**/*.js.map'],
        },
        telemetry: mode === 'production',
        // debug: mode === 'production', // to check if filesToDeleteAfterUpload works as expected
        silent: mode !== 'production',
        errorHandler: (err) => {
          console.warn(err)
        },
      }),
    ],
  }
})
lforst commented 7 months ago

Closing this since I think you solved the problem. Feel free to ping me in case you have any other questions!