Skip to content

Instantly share code, notes, and snippets.

@benoitguigal
Last active February 5, 2020 10:06
Show Gist options
  • Save benoitguigal/137075b0d83d2d0d061d2f8c24be6c8c to your computer and use it in GitHub Desktop.
Save benoitguigal/137075b0d83d2d0d061d2f8c24be6c8c to your computer and use it in GitHub Desktop.
server.ts
const sentryMiddleware = () =>
sentry<GraphQLContext>({
config: {
dsn: SENTRY_DSN,
environment: NODE_ENV,
integrations: [new CaptureConsole({ levels: ["error"] })]
},
forwardErrors: true,
withScope: (scope, error, context) => {
const reqUser = !!context.user ? context.user.email : "anonymous";
scope.setUser({
email: reqUser
});
scope.setExtra("body", context.req.body);
scope.setExtra("origin", context.req.headers.origin);
scope.setExtra("user-agent", context.req.headers["user-agent"]);
scope.setExtra("ip", context.req.headers["x-real-ip"]);
scope.setTag("service", "api");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment