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

GraphQL plug-in prevents Sentry middleware from catching errors #10354

Closed
jorisw opened this issue May 20, 2021 · 14 comments
Closed

GraphQL plug-in prevents Sentry middleware from catching errors #10354

jorisw opened this issue May 20, 2021 · 14 comments
Assignees
Labels
issue: bug Issue reporting a bug severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: plugin:sentry Source is plugin/sentry package status: confirmed Confirmed by a Strapi Team member or multiple community members

Comments

@jorisw
Copy link
Contributor

jorisw commented May 20, 2021

Bug report

Describe the bug

Because the Sentry plug-in's middleware comes after that of the GraphQL plug-in, and the GraphQL plug-in catches fatal errors for reporting in the response, fatal errors as part of GraphQL operations are not reported to Sentry.

Other middlewares are likely to suffer from the GraphQL plug-in catching the errors, too.

Steps to reproduce the behavior

  1. Enable the GraphQL plug-in
  2. Enable the Sentry plug-in
  3. Put a sendError() call somewhere and trigger the call
  4. Notice the error is reported to Sentry
  5. Put some nonsensical code in a controller or model such as hi()
  6. Do a GraphQL query that reaches this code
  7. Notice the error is part of the GraphQL response
  8. Notice the error is not caught by the Sentry plug-in/middleware, therefore not reported to Sentry

Expected behavior

I expect fatal errors to be both reported by the GraphQL response, as well as reported by the Sentry plug-in to Sentry

Screenshots

These console logs, added to node_modules/strapi-sentry-plugin/middlewares/sentry/index.js, are not logged when calling a GraphQL query that triggers an error:

image

I also tried to put the Sentry middleware before that of GraphQL, to no avail, probably because we're talking about middlewares as part of plug-ins:

// config/middleware.js

module.exports = () => ({
  load: { order: ['sentry', 'graphql'] },
})

System

  • Node.js version: v14.15.0
  • Yarn version: 1.22.5
  • Strapi version: 3.6.2
  • Database: MySQL
  • Operating system: macOS 11.3
@jorisw jorisw changed the title Sentry plug-in doesn't catch errors in GraphQL operations GraphQL plug-in prevents Sentry middleware from catching errors May 20, 2021
@remidej remidej self-assigned this May 21, 2021
@remidej remidej added source: plugin:sentry Source is plugin/sentry package status: confirmed Confirmed by a Strapi Team member or multiple community members labels May 21, 2021
@derrickmehaffy derrickmehaffy added severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve issue: bug Issue reporting a bug labels May 24, 2021
@derrickmehaffy derrickmehaffy added this to To Review in [Experiment] Issue Board via automation May 24, 2021
@jorisw
Copy link
Contributor Author

jorisw commented May 25, 2021

FWIW, I think this issue represents a broader problem in the design of the middlewares-in-plugins queuing system rather than a bug in the Sentry plug-in.

@derrickmehaffy
Copy link
Member

FWIW, I think this issue represents a broader problem in the design of the middlewares-in-plugins queuing system rather than a bug in the Sentry plug-in.

Agreed, we are discussing it internally but we should summarize that discussion here @remidej

@IvanCoronado
Copy link

@jorisw I am facing exactly this problem. Did you find some workaround?

My best temporal solution by now is wrapping my controllers with a try/catch and manually send the error to Sentry but it's too much extra code...

@jorisw
Copy link
Contributor Author

jorisw commented Jul 5, 2021

@IvanCoronado Indeed that's what we're doing.

@derrickmehaffy Any updates on this?

@ralphsomeday
Copy link
Contributor

@jorisw I am facing exactly this problem. Did you find some workaround?

My best temporal solution by now is wrapping my controllers with a try/catch and manually send the error to Sentry but it's too much extra code...

@alexandrebodin any idea how we can solve this as the Sentry plugin is worthless when using Strapi with Graphql? thanks

@derrickmehaffy
Copy link
Member

@IvanCoronado Indeed that's what we're doing.

@derrickmehaffy Any updates on this?

@remidej is currently out of the office for a while, let me poke the team and see if it's going to be reassigned to someone else.

@ralphsomeday
Copy link
Contributor

@derrickmehaffy any update on this one?

@derrickmehaffy
Copy link
Member

@remidej any information you can offer here?

@remidej
Copy link
Contributor

remidej commented Jul 21, 2021

Not yet sorry 😕

@ralphsomeday
Copy link
Contributor

@remidej when do you think you will have time to look into it?

@derrickmehaffy
Copy link
Member

This issue has been mentioned on Strapi Community Forum. There might be relevant details there:

https://forum.strapi.io/t/how-can-i-persist-logging-beyond-application-running-scope/8595/3

@ralphsomeday
Copy link
Contributor

@derrickmehaffy in current Strapi version 3.6.x Sentry plugin is unusable... Is anyone from the core team looking into it? thanks

@jorisw
Copy link
Contributor Author

jorisw commented Dec 16, 2021

@jorisw I am facing exactly this problem. Did you find some workaround?

My best temporal solution by now is wrapping my controllers with a try/catch and manually send the error to Sentry but it's too much extra code...

We were able to get rid of try/catch blocks all over the controllers, by adding the following to extensions/graphql/config/settings.js.

There may be a better place to put this than in extensions/, we haven't looked into that yet.

module.exports = {
  apolloServer: {
    plugins: [
      {
        requestDidStart() {
          return {
            didEncounterErrors(apolloContext) {
              const koaContext = apolloContext.context.context
              apolloContext.errors.forEach(error => {
                strapi.log.error(error)
                strapi.sentry.captureRequestError(error, koaContext)
              })
            },
          }
        },
      },
    ],
  },
}

Perhaps the Strapi team could use such an approach to fix their Sentry plug-in.

@derrickmehaffy
Copy link
Member

Fixed in v4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Issue reporting a bug severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: plugin:sentry Source is plugin/sentry package status: confirmed Confirmed by a Strapi Team member or multiple community members
Projects
Archived in project
Development

No branches or pull requests

5 participants