All Projects → BrunoScheufler → Graphql Middleware Sentry

BrunoScheufler / Graphql Middleware Sentry

Licence: mit
🗃 A GraphQL Middleware plugin for Sentry.

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to Graphql Middleware Sentry

Sentry
Bruteforce attack blocker (ssh, FTP, SMTP, and more)
Stars: ✭ 58 (-58.87%)
Mutual labels:  sentry
Raven.cr
Raven is a Crystal client for Sentry
Stars: ✭ 96 (-31.91%)
Mutual labels:  sentry
Sentry Mina
小程序 Sentry SDK
Stars: ✭ 124 (-12.06%)
Mutual labels:  sentry
Sentry Clj
Sentry SDK for Clojure
Stars: ✭ 63 (-55.32%)
Mutual labels:  sentry
Myapp
React Native 工程实践
Stars: ✭ 83 (-41.13%)
Mutual labels:  sentry
Logrus
Hooks for logrus logging
Stars: ✭ 110 (-21.99%)
Mutual labels:  sentry
Api server boilerplate
typescript express board boilerplate using routing controller
Stars: ✭ 52 (-63.12%)
Mutual labels:  sentry
Quicklogger
Library for logging on files, console, memory, email, rest, eventlog, syslog, slack, telegram, redis, logstash, elasticsearch, influxdb, graylog, Sentry, Twilio, ide debug messages and throw events for Delphi/Firemonkey/freepascal/.NET (Windows/Linux/OSX/IOS/Android).
Stars: ✭ 137 (-2.84%)
Mutual labels:  sentry
Raven Aiohttp
An aiohttp transport for raven-python
Stars: ✭ 92 (-34.75%)
Mutual labels:  sentry
Nest Raven
Sentry Raven Module for Nest.js Framework
Stars: ✭ 123 (-12.77%)
Mutual labels:  sentry
Sentry Wizard
Sentry Project Setup Wizard
Stars: ✭ 78 (-44.68%)
Mutual labels:  sentry
Ember Cli Sentry
Error tracking via Sentry for Ember.js apps
Stars: ✭ 81 (-42.55%)
Mutual labels:  sentry
Attic Sentry
Mirror of Apache Sentry
Stars: ✭ 109 (-22.7%)
Mutual labels:  sentry
Apollo Link Sentry
Apollo Link middleware which enriches SentryJS with GraphQL data
Stars: ✭ 63 (-55.32%)
Mutual labels:  sentry
Gatsby Starter Lumen
A constantly evolving and thoughtful architecture for creating static blogs.
Stars: ✭ 1,797 (+1174.47%)
Mutual labels:  sentry
Sentry
Middleware to integrate with sentry crash reporting.
Stars: ✭ 55 (-60.99%)
Mutual labels:  sentry
Magento2 Sentry
Magento 2 module to log to Sentry
Stars: ✭ 99 (-29.79%)
Mutual labels:  sentry
Raven Python
Raven is the legacy Python client for Sentry (getsentry.com) — replaced by sentry-python
Stars: ✭ 1,677 (+1089.36%)
Mutual labels:  sentry
Sentry Self Hosted
Self-host Sentry for $5 per month
Stars: ✭ 132 (-6.38%)
Mutual labels:  sentry
Sentry Php
The official PHP SDK for Sentry (sentry.io)
Stars: ✭ 1,591 (+1028.37%)
Mutual labels:  sentry

graphql-middleware-sentry

CircleCI npm version

GraphQL Middleware plugin for Sentry.

Usage

With GraphQL Yoga

import { GraphQLServer } from 'graphql-yoga'
import { sentry } from 'graphql-middleware-sentry'

const typeDefs = `
  type Query {
    hello: String!
    bug: String!
  }
`

const resolvers = {
  Query: {
    hello: () => `Hey there!`
    bug: () => {
      throw new Error(`Many bugs!`)
    }
  }
}

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

const server = GraphQLServer({
  typeDefs,
  resolvers,
  middlewares: [sentryMiddleware]
})

server.start(() => `Server running on http://localhost:4000`)

Using a Sentry instance

In cases where you want to use your own instance of Sentry to use it in other places in your application you can pass the sentryInstance. The config property should not be passed as an option.

Example usage with a Sentry instance

Sentry.init({
  dsn: process.env.SENTRY_DSN,
})

const sentryMiddleware = sentry({
  sentryInstance: Sentry,
  withScope: (scope, error, context) => {
    scope.setExtra('origin', context.request.headers.origin)
  },
})

API & Configuration

export interface Options<Context> {
  sentryInstance?: Sentry
  config?: Sentry.NodeOptions
  withScope?: ExceptionScope<Context>
  captureReturnedErrors?: boolean
  forwardErrors?: boolean
  reportError?: (res: Error | any) => boolean
}

function sentry<Context>(options: Options<Context>): IMiddlewareFunction

Sentry context

To enrich events sent to Sentry, you can modify the context. This can be done using the withScope configuration option.

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

type ExceptionScope<Context> = (
  scope: Sentry.Scope,
  error: Error,
  context: Context,
) => void

Filtering Out Custom Errors

To filter out custom errors thrown by your server (such as "You Are Not Logged In"), use the reportError option and return a boolean for whether or not the error should be sent to sentry.

class CustomError extends Error {}

const sentryMiddleware = sentry({
  reportError: (res) => {
    // you can check the error message strings
    if (res.message === 'You Are Not Logged In') {
      return false;
    }

    // or extend the error type and create a custom error
    if (res instanceof CustomError) {
      return false;
    }

    return true;
  }
})

Options

property required description
sentryInstance false Sentry's instance
config false Sentry's config object
withScope false Function to modify the Sentry context to send with the captured error.
captureReturnedErrors false Capture errors returned from other middlewares, e.g., graphql-shield returns errors from rules and resolvers
forwardErrors false Should middleware forward errors to the client or block them.
reportError false Function that passes res as the parameter and accepts a boolean callback for whether or not the error should be captured

Note

If sentryInstance is not passed then config.dsn is required and vice-versa.

License

This project is licensed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].