sentrusgin

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: 5 Imported by: 0

README

sentrusgin

Example

import (
    "github.com/orandin/sentrus"
    sentrusgin "github.com/orandin/sentrus/gin"
)

// Set up Sentry here

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

app := gin.Default()

app.Use(func(ctx *gin.Context) {
    if hub := sentrygin.GetHubFromContext(ctx); hub != nil {
        hub.Scope().SetTag("someRandomTag", "maybeYouNeedIt")
    }
    ctx.Next()
})

app.GET("/", func(ctx *gin.Context) {
    logHandler := logrus.WithContext(ctx) // Inject gin.Context into logrus.Entry
    logHandler.Warn("It's a test")

    ctx.Status(http.StatusOK)
})

app.GET("/foo", func(ctx *gin.Context) {
    logHandler := logrus.WithContext(ctx)
    logHandler.WithError(fmt.Errorf("test error")).Warn("It's a test with error")

	ctx.Status(http.StatusOK)
})

app.Run(":3000")

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