-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlevels.go
56 lines (52 loc) · 1.46 KB
/
levels.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package logger
import (
"net/http"
"github.com/getsentry/sentry-go"
"go.uber.org/zap/zapcore"
)
func SentryLevel(level zapcore.Level) sentry.Level {
switch level {
case zapcore.DebugLevel:
return sentry.LevelDebug
case zapcore.InfoLevel:
return sentry.LevelInfo
case zapcore.WarnLevel:
return sentry.LevelWarning
case zapcore.ErrorLevel, zapcore.DPanicLevel:
return sentry.LevelError
case zapcore.PanicLevel, zapcore.FatalLevel, zapcore.InvalidLevel:
return sentry.LevelFatal
default:
return sentry.LevelDebug
}
}
//nolint:cyclop
func SpanStatus(httpCode int) sentry.SpanStatus {
if http.StatusOK <= httpCode && httpCode < 299 {
return sentry.SpanStatusOK
}
switch httpCode {
case http.StatusBadRequest:
return sentry.SpanStatusInvalidArgument
case http.StatusUnauthorized:
return sentry.SpanStatusUnauthenticated
case http.StatusForbidden:
return sentry.SpanStatusPermissionDenied
case http.StatusNotFound:
return sentry.SpanStatusNotFound
case http.StatusConflict:
return sentry.SpanStatusAlreadyExists
case 499: // nginx specific: client has closed connection
return sentry.SpanStatusCanceled
case http.StatusInternalServerError:
return sentry.SpanStatusInternalError
case http.StatusNotImplemented:
return sentry.SpanStatusUnimplemented
case http.StatusServiceUnavailable:
return sentry.SpanStatusUnavailable
case http.StatusGatewayTimeout:
return sentry.SpanStatusDeadlineExceeded
default:
return sentry.SpanStatusUnknown
}
}