Browse Source

Add RollBar error reporting

Volodymyr Tkach 2 years ago
parent
commit
313f558c84
3 changed files with 17 additions and 0 deletions
  1. 1 0
      go.mod
  2. 8 0
      go.sum
  3. 8 0
      utils/http/logger/logger.go

+ 1 - 0
go.mod

@@ -5,6 +5,7 @@ go 1.18
 require (
 	github.com/onsi/ginkgo v1.16.5
 	github.com/onsi/gomega v1.19.0
+	github.com/rollbar/rollbar-go v1.4.4
 	github.com/vladimirok5959/golang-server-sessions v1.0.9
 )
 

+ 8 - 0
go.sum

@@ -1,4 +1,5 @@
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
 github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
@@ -28,9 +29,14 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
 github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
 github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
 github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/rollbar/rollbar-go v1.4.4 h1:XtkPvjEbGTYJA04eXyGabCXk3jL+sEZTlSdTLbzsHoI=
+github.com/rollbar/rollbar-go v1.4.4/go.mod h1:kLQ9gP3WCRGrvJmF0ueO3wK9xWocej8GRX98D8sa39w=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
+github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
+github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/vladimirok5959/golang-server-sessions v1.0.9 h1:oGj3jfpIo5PtWojeGDexDtTmaaZtSY/vH2PcwZIqWNI=
 github.com/vladimirok5959/golang-server-sessions v1.0.9/go.mod h1:w0JRthleTg5D4lY32iczfuUfKCXpbgUiLXHhIUFyY4o=
 github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
@@ -87,3 +93,5 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
 gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

+ 8 - 0
utils/http/logger/logger.go

@@ -5,9 +5,12 @@ import (
 	"net/http"
 	"time"
 
+	"github.com/rollbar/rollbar-go"
 	"github.com/vladimirok5959/golang-utils/utils/http/helpers"
 )
 
+var RollBarEnabled = false
+
 type ResponseWriter struct {
 	http.ResponseWriter
 	Status int
@@ -26,6 +29,11 @@ func LogRequests(handler http.Handler) http.Handler {
 			Status:         http.StatusOK,
 		}
 		handler.ServeHTTP(nw, r)
+		if RollBarEnabled {
+			if !(nw.Status == http.StatusOK || nw.Status == http.StatusNotFound) {
+				rollbar.Error(r, nw)
+			}
+		}
 		log.Printf(
 			"\"%s\" \"%s %s\" %d \"%.3f ms\"\n",
 			helpers.ClientIP(r), r.Method, r.URL, nw.Status, time.Since(start).Seconds(),