sentrushttp

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2022 License: MIT Imports: 3 Imported by: 0

README

sentrushttp

Example

import (
    "github.com/orandin/sentrus"
    sentrushttp "github.com/orandin/sentrus/http"
)

// Set up Sentry here

// Add hook
logrus.AddHook(sentrus.NewHook(
    []logrus.Level{logrus.WarnLevel, logrus.ErrorLevel},
    sentrus.WithCustomCaptureLog(sentrushttp.CaptureLog),
))

enhanceSentryEvent := func(handler http.HandlerFunc) http.HandlerFunc {
    return func(rw http.ResponseWriter, r *http.Request) {
        if hub := sentry.GetHubFromContext(r.Context()); hub != nil {
            hub.Scope().SetTag("someRandomTag", "maybeYouNeedIt")
        }
        handler(rw, r)
	}
}

http.HandleFunc("/", sentryHandler.HandleFunc(
    enhanceSentryEvent(func(rw http.ResponseWriter, r *http.Request) {
        logHandler := logrus.WithContext(r.Context())
        logHandler.Warn("Ceci est un test")

        rw.WriteHeader(http.StatusOK)
    }),
))

http.HandleFunc("/foo", sentryHandler.HandleFunc(
    enhanceSentryEvent(func(rw http.ResponseWriter, r *http.Request) {
        panic("y tho")
    }),
))

fmt.Println("Listening and serving HTTP on :3000")

if err := http.ListenAndServe(":3000", nil); err != nil {
    panic(err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureLog

func CaptureLog(entry *logrus.Entry, defaultHub *sentry.Hub, tags map[string]string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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