getsentry / sentry-javascript

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

@sentry/nestjs graphql crashes the application on 404 #14314

Open jhmen opened 5 hours ago

jhmen commented 5 hours ago

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nestjs

SDK Version

8.38.0

Framework Version

nestjs 10.4.1

Link to Sentry event

No response

Reproduction Example/SDK Setup

instrument.ts:

import * as Sentry from '@sentry/nestjs';
import { nodeProfilingIntegration } from '@sentry/profiling-node';
import * as process from 'node:process';

Sentry.init({
  // We cant use the config service here, because we need to initialize Sentry before the app starts
  dsn: process.env.SENTRY_DSN,
  integrations: [nodeProfilingIntegration()],
  // Tracing
  tracesSampleRate: +process.env.SENTRY_TRACES_SAMPLE_RATE || 0.1, //  Capture 100% of the transactions

  // Set sampling rate for profiling - this is relative to tracesSampleRate
  profilesSampleRate: +process.env.PROFILES_SAMPLE_RATE || 0.1,

  environment: process.env.SENTRY_ENVIRONMENT,
});

app.module.ts:

@Module({
  imports: [
    SentryModule.forRoot(),
  ],
  providers: [
    {
      provide: APP_FILTER,
      useClass: SentryGlobalGraphQLFilter,
    },
  ],
})

Steps to Reproduce

  1. Create a nestjs + graphql application
  2. Install sentry
  3. Setup sentry like it is shown in the docs
  4. Start the application
  5. Call a url like /fav.ico which does not exist
  6. The application crashes

Expected Result

The application should not crash

Actual Result

The application crashes. It does not exit, but no request can be made, and the application is not responding.

2024-11-15T06:30:28.009579112Z [2024-11-15T06:30:28.007Z] ERROR    NotFoundException: Cannot GET /favicon.ico
2024-11-15T06:30:28.009619610Z     at callback (/usr/src/<application>/node_modules/.pnpm/@nestjs+core@10.4.1_@nestjs+common@10.4.1_class-transformer@0.5.1_class-validator@0.13.2_refl_gwypgs4obw5tw3bpishsnyaznu/node_modules/@nestjs/core/router/routes-resolver.js:77:19)
2024-11-15T06:30:28.009623899Z     at /usr/src/<application>/node_modules/.pnpm/@nestjs+core@10.4.1_@nestjs+common@10.4.1_class-transformer@0.5.1_class-validator@0.13.2_refl_gwypgs4obw5tw3bpishsnyaznu/node_modules/@nestjs/core/router/router-proxy.js:9:23
2024-11-15T06:30:28.009627495Z     at Layer.handle [as handle_request] (/usr/src/<application>/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/layer.js:95:5)
2024-11-15T06:30:28.009630892Z     at trim_prefix (/usr/src/<application>/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/index.js:328:13)
2024-11-15T06:30:28.009634259Z     at /usr/src/<application>/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/index.js:286:9
2024-11-15T06:30:28.009637755Z     at Function.process_params (/usr/src/<application>/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/index.js:346:12)
2024-11-15T06:30:28.009640951Z     at next (/usr/src/<application>/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/index.js:280:10)
2024-11-15T06:30:28.009643907Z     at urlencodedParser (/usr/src/<application>/node_modules/.pnpm/body-parser@1.20.2/node_modules/body-parser/lib/types/urlencoded.js:91:7)
2024-11-15T06:30:28.009647093Z     at Layer.handle [as handle_request] (/usr/src/<application>/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/layer.js:95:5)
2024-11-15T06:30:28.009650209Z     at trim_prefix (/usr/src/<application>/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/index.js:328:13)
chargome commented 3 hours ago

Hey @jhmen thanks for reporting this, could you try using SentryGlobalGenericFilter instead and check if you're facing the same issue?

jhmen commented 3 hours ago

Hey @chargome switching to the SentryGlobalGenericFilter resolves the issue.

chargome commented 3 hours ago

Good to hear! Will update the docs accordingly soon, SentryGlobalGenericFilter was added recently and handles both gql and http errors.

jhmen commented 2 hours ago

Sounds Greate i will switch our applications accordently.