diff options
Diffstat (limited to 'internal/errortracking/errortracking.go')
-rw-r--r-- | internal/errortracking/errortracking.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/internal/errortracking/errortracking.go b/internal/errortracking/errortracking.go new file mode 100644 index 00000000..d82674cc --- /dev/null +++ b/internal/errortracking/errortracking.go @@ -0,0 +1,27 @@ +package errortracking + +import ( + "net/http" + + "gitlab.com/gitlab-org/labkit/errortracking" +) + +// CaptureOption alias to avoid importing labkit/errortracking in internal packages +type CaptureOption = errortracking.CaptureOption + +// WithField alias to avoid importing labkit/errortracking in internal packages +func WithField(key, value string) CaptureOption { + return errortracking.WithField(key, value) +} + +// CaptureErrWithReqAndStackTrace calls labkit's errortracking function and attaches the request, stack trace and any additional fields +func CaptureErrWithReqAndStackTrace(err error, r *http.Request, fields ...errortracking.CaptureOption) { + opts := append( + fields, + errortracking.WithContext(r.Context()), + errortracking.WithRequest(r), + errortracking.WithStackTrace(), + ) + + errortracking.Capture(err, opts...) +} |