GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [NestJS] Sentry Error filter doesn't work in GraphQL context · Issue #13473 · getsentry/sentry-javascript

[NestJS] Sentry Error filter doesn't work in GraphQL context #13473

New issue
Copy link
New issue
Copy link
Closed
#13545
Closed
[NestJS] Sentry Error filter doesn't work in GraphQL context#13473
#13545
Copy link
Assignees
nicohrubec
Labels
Bug

Description

@lforst
lforst
opened on Aug 27, 2024
Issue body actions

Hey @nicohrubec - we are using GraphQL/NestJS and it looks like the newest version of the Sentry SDK for NestJS doesn't work for this. Specifically - I think it is somewhat related to this change regressing from #12128, or this comment #12128 (comment)

It doesn't look like there is a way to specify a different base filter in the new version of the NestJS/Sentry SDK like in setupNestErrorHandler - which btw, should that be considered deprecated?

I'm wondering if SentryGlobalFilter needs to allow configuring a custom base filter here https://github.com/getsentry/sentry-javascript/blob/develop/packages/nestjs/src/setup.ts#L63 as you are able to do here

sentry-javascript/packages/node/src/integrations/tracing/nest/nest.ts

Line 55 in 615c670

export function setupNestErrorHandler(app: MinimalNestJsApp, baseFilter: NestJsErrorFilter): void {

With the current impl - we are consistently getting

{
      "query": "query {\n  triggerError\n}",
      "variables": {},
      "errors": [
        {
          "message": "response.status is not a function",
          "locations": [
            {
              "line": 2,
              "column": 3
            }
          ],
          "path": [
            "triggerError"
          ]
        }
      ]
    }

Let me know if you'd like me to open a new issue for this!

Edit - I confirmed monkey-patching the BaseExceptionFilter to ExternalExceptionFilter fixed the issue on GraphQL requests for us

diff --git a/build/cjs/setup.js b/build/cjs/setup.js
index 119735398bb49a01b1c941045a809edd45b32fdc..b06228c7d71288ef53f140de1890e9e4fefe7477 100644
--- a/build/cjs/setup.js
+++ b/build/cjs/setup.js
@@ -6,6 +6,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
 
 const common = require('@nestjs/common');
 const core = require('@nestjs/core');
+const filter = require('@nestjs/core/exceptions/external-exception-filter');
 const microservices = require('@nestjs/microservices');
 const core$1 = require('@sentry/core');
 const utils = require('@sentry/utils');
@@ -47,7 +48,7 @@ common.Injectable()(SentryTracingInterceptor);
 /**
  * Global filter to handle exceptions and report them to Sentry.
  */
-class SentryGlobalFilter extends core.BaseExceptionFilter {
+class SentryGlobalFilter extends filter.ExternalExceptionFilter {
    static  __initStatic2() {this.__SENTRY_INTERNAL__ = true;}
 
   /**

Originally posted by @ysuhaas in #12351

Reacted by Daniel Hritzkiv and Suhaas Yerramreddy

Activity

  1. lforst
    assigned
    nicohrubec
    on Aug 27, 2024
  2. nicohrubec
    added
    Package: nestjs
    on Aug 28, 2024
  3. nicohrubec commented on Aug 28, 2024

    @nicohrubec
    nicohrubec
    on Aug 28, 2024
    Member
    More actions

    For now I think the solution here should be to just add an additional variation of the SentryGlobalFilter that can handle GraphQL contexts (extending ExternalExceptionFilter). However, with this setup users might still run into issues in certain scenarios as was already discussed before. ref In these cases custom filters are needed. Currently the way to work around this is to use the WithSentry() decorator.

    In the future, we can think about providing a factory-method that takes an arbitrary filter and proxies it with some logic to report errors. Instead of useClass developers can then use useFactory to add the proxied filter to their application.

  4. ralexandr commented on Aug 28, 2024

    @ralexandr
    ralexandr
    on Aug 28, 2024
    More actions

    I've met same issue, but withSentry could not resolve it
    When i add withSentry decorator to my custom AllExceptionsFilter, "exception" and "host" variables are undefined.

     async catch(exception, host) {
        console.log(exception, host);  // This will return "undefined undefined" to stdout
    }
    
    Reacted by Jonathan Bonnefoy
  5. getsantry
    added
    Waiting for: Product Owner
    on Aug 28, 2024
  6. getsantry
    added this to GitHub Issues with 👀 3on Aug 28, 2024
  7. getsantry
    moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Aug 28, 2024
  8. nicohrubec commented on Aug 29, 2024

    @nicohrubec
    nicohrubec
    on Aug 29, 2024
    Member
    More actions

    @ralexandr Did you put the decorator on the catch directly or on top of the AllExceptionsFilter?

  9. getsantry
    removed
    Waiting for: Product Owner
    on Aug 29, 2024
  10. getsantry
    moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Aug 29, 2024
  11. nicohrubec
    linked a pull request that will close this issuefeat(nestjs): Add `SentryGlobalGraphQLFilter` #13545on Sep 2, 2024
  12. nicohrubec
    closed this as completedin #13545on Sep 2, 2024
  13. nicohrubec commented on Sep 2, 2024

    @nicohrubec
    nicohrubec
    on Sep 2, 2024
    Member
    More actions

    Hey everyone, we added a new SentryGlobalGraphQLFilter, which is essentially a reimplementation of the NestJS ExternalExceptionFilter. This filter should be used in NestJS + GraphQL applications.

    In our e2e sample applications, this seems to resolve this issue, but let us know if you run into any further troubles.

  14. hernandezka commented on Dec 11, 2024

    @hernandezka
    hernandezka
    on Dec 11, 2024
    More actions

    hi @nicohrubec, have a question, is there any Filter that can work with graphql + rest? I did some test with SentryGlobalGraphQLFilter and with SentryGlobalFilter, but looks like each of them have issues.
    For example, when I used SentryGlobalGraphQLFilter, when we throw an exception from REST modules, the response seems to be blocked, and don't resolve/rejects to the requester.
    In the other hand, when I used SentryGlobalFilter, the errors thowed by graphql module, lost the sent error messages.

    Also, I tried with SentryGlobalGenericFilter, seems to work OK, but seems that it is logging all the "expected" exceptions in sentry console, which is not what we need.
    any thoughs?
    Best regards 😄

  15. lforst commented on Dec 12, 2024

    @lforst
    lforst
    on Dec 12, 2024
    ContributorAuthor
    More actions

    @hernandezka what version of the SDK are you on? The current recommended way to set up error filters is outlined here https://docs.sentry.io/platforms/javascript/guides/nestjs/#use - it somewhat recently changed.

    If you have already followed these docs, would you mind giving a specific example with code that doesn't work as expected? Ideally in a new issue so that we can properly track. (also so that Nico the intern can go back to doing university assignments without being bugged on github 😂)

    Reacted by Karla Hernández
  16. hernandezka commented on Dec 12, 2024

    @hernandezka
    hernandezka
    on Dec 12, 2024
    More actions

    @lforst thanks for the quick response!
    Will check the docs and open a new ticket 😄
    Best regards

  17. ghost added
    Bug
    on Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @nicohrubec
    nicohrubec

Labels

Bug

Projects

  • GitHub Issues with 👀 3
    Status
    No status
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.