scout

package module
v0.0.0-...-4c3b0cb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2019 License: MIT Imports: 6 Imported by: 0

README

scout

scout is a middleware for the chi-router to report events to sentry.io using the sentry-go client.

The sentry-go client must be initialized with sentry.Init.

This middleware also replaces middleware.Recoverer which should not be used alongside with this middleware.

Here is an example on how to use the middleware:

import (
	"net/http"

	"github.com/go-chi/chi"
	"github.com/zy4/scout"
)

r := chi.NewRouter()

// Use the middleware in the router
r.Use(scout.SentryRecovery)

r.Get("/", func(w http.ResponseWriter, r *http.Request) {
    panic("caught")
})

Attribution

scout was created to emulate the raven-go middleware raven-chi for the official sentry-go SDK since raven-go is deprecated.

Documentation

Overview

Package scout implement a middleware for report panic to sentry.io.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SentryRecovery

func SentryRecovery(handler http.Handler) http.Handler

SentryRecovery recover from panic, report the error back to sentry, log it, and return an internal server error back to the user.

Example
package main

import (
	"net/http"

	"github.com/go-chi/chi"
	"github.com/zy4/scout"
)

func main() {
	r := chi.NewRouter()

	// Apply the middleware to the router
	r.Use(scout.SentryRecovery)

	r.Get("/", func(w http.ResponseWriter, r *http.Request) {
		panic("caught")
	})
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL