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/nestjs graphql crashes the application on 404 #14314

Open
3 tasks done
jhmen opened this issue Nov 15, 2024 · 4 comments · May be fixed by getsentry/sentry-docs#11830
Open
3 tasks done

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

jhmen opened this issue Nov 15, 2024 · 4 comments · May be fixed by getsentry/sentry-docs#11830
Labels
Package: nestjs Issues related to the Sentry Nestjs SDK

Comments

@jhmen
Copy link

jhmen commented Nov 15, 2024

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)
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Nov 15, 2024
@github-actions github-actions bot added the Package: nestjs Issues related to the Sentry Nestjs SDK label Nov 15, 2024
@chargome
Copy link
Member

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

@jhmen
Copy link
Author

jhmen commented Nov 15, 2024

Hey @chargome switching to the SentryGlobalGenericFilter resolves the issue.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Nov 15, 2024
@chargome
Copy link
Member

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

@jhmen
Copy link
Author

jhmen commented Nov 15, 2024

Sounds Greate i will switch our applications accordently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nestjs Issues related to the Sentry Nestjs SDK
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants