1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-01-18 11:12:10 +02:00
2021-05-07 17:10:21 +06:00

40 lines
660 B
Go

package sentry
import (
"net/http"
"time"
"github.com/getsentry/sentry-go"
"github.com/imgproxy/imgproxy/v2/config"
)
var (
enabled bool
timeout = 5 * time.Second
)
func Init() {
if len(config.SentryDSN) > 0 {
sentry.Init(sentry.ClientOptions{
Dsn: config.SentryDSN,
Release: config.SentryRelease,
Environment: config.SentryEnvironment,
})
enabled = true
}
}
func Report(err error, req *http.Request) {
if enabled {
hub := sentry.CurrentHub().Clone()
hub.Scope().SetRequest(req)
hub.Scope().SetLevel(sentry.LevelError)
eventID := hub.CaptureException(err)
if eventID != nil {
hub.Flush(timeout)
}
}
}