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

replace static `extras` option with a more dynamic `withScope` option #34

Merged
merged 2 commits into from Dec 7, 2018

Conversation

Projects
None yet
3 participants
@koenpunt
Contributor

koenpunt commented Dec 3, 2018

Instead of adding string parsing using lodash, I've replaced the extras option with a withScope option.

The withScope option is a function that is called with the Sentry scope, the error, and the GraphQL context.

Using this option you can achieve the same as what previously was possible with the extras option + all other context options Sentry provides.

I've also removed the dsn argument, since that simply is a property of the config object.

Example usage:

const sentryMiddleware = sentry<Context>({
  config: {
    dsn: process.env.SENTRY_DSN,
    environment: process.env.NODE_ENV,
    release: process.env.npm_package_version,
  },
  withScope: (scope, error, context) => {
    scope.setUser({
      id: context.authorization.userId,
    });
    scope.setExtra('body', context.request.body)
    scope.setExtra('origin', ctx.request.headers.origin)
    scope.setExtra('user-agent', context.request.headers['user-agent'])
  },
});

@koenpunt koenpunt force-pushed the unitedwardrobe:function-extra branch from 01379e8 to 6cb43b6 Dec 3, 2018

@koenpunt koenpunt changed the title from change extras to be a function callback, remove dsn function argument to change extras to be a function callback, make dsn function argument optional Dec 3, 2018

@koenpunt koenpunt force-pushed the unitedwardrobe:function-extra branch 3 times, most recently from f37452a to b0e9a6e Dec 3, 2018

@koenpunt koenpunt changed the title from change extras to be a function callback, make dsn function argument optional to replace static `extras` option with a more dynamic `withScope` option Dec 3, 2018

@koenpunt koenpunt force-pushed the unitedwardrobe:function-extra branch from b0e9a6e to 91e34ef Dec 3, 2018

replace static `extras` option with a more dynamic `withScope` option
The `withScope` option is a function that is called with the Sentry scope, the error, and the GraphQL context.

Using this option you can achieve the same as what previously was possible with the `extras` option + all other context options Sentry gives.

@koenpunt koenpunt force-pushed the unitedwardrobe:function-extra branch from 91e34ef to 539ca6f Dec 3, 2018

@frandiox

This comment has been minimized.

frandiox commented Dec 5, 2018

Thanks for this, I was going to make the same PR 😅
This is also useful to set error level depending on the error itself. Like, I don't want to be notified for 400 errors, for example :)

@koenpunt

This comment has been minimized.

Contributor

koenpunt commented Dec 5, 2018

@frandiox By now I've created an even more generic solution, which doesn't depend on Sentry or lodash, and can be used with any other error reporting tool too; https://github.com/unitedwardrobe/graphql-middleware-error-handler/

@maticzav maticzav merged commit 9919309 into maticzav:master Dec 7, 2018

@maticzav

This comment has been minimized.

Owner

maticzav commented Dec 7, 2018

🎉 This PR is included in version 2.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@maticzav maticzav added the released label Dec 7, 2018

@maticzav

This comment has been minimized.

Owner

maticzav commented Dec 7, 2018

Hey @koenpunt 👋,

Thank you for creating this PR, I just pushed a new version. I am not all that familiar with sentry and would love to add you as a collaborator if you would be ready to help. 🙂

@koenpunt koenpunt deleted the unitedwardrobe:function-extra branch Dec 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment