Skip to content

Commit

Permalink
chore: update the rollbar SDK (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
appleboy authored and easonlin404 committed Nov 20, 2019
1 parent 9bf7c95 commit ca870f0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
coverage.txt
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
[![GoDoc](https://godoc.org/github.com/gin-contrib/rollbar?status.svg)](https://godoc.org/github.com/gin-contrib/rollbar)
[![Join the chat at https://gitter.im/gin-gonic/gin](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/gin-gonic/gin)

Middleware to integrate with [rollbar](https://rollbar.com/) error monitoring. It uses [roll](https://github.com/stvp/roll) client for Go that reports errors and logs messages.
Middleware to integrate with [rollbar](https://rollbar.com/) error monitoring. It uses [rollbar-go](https://github.com/rollbar/rollbar-go) SDK that reports errors and logs messages.

## Usage

### Start using it

Download and install it:

```sh
Expand All @@ -24,20 +22,21 @@ Import it in your code:
import "github.com/gin-contrib/rollbar"
```

### Example
## Example

```go
package main

import (
"github.com/gin-contrib/rollbar"
"github.com/gin-gonic/gin"
"github.com/stvp/roll"

roll "github.com/rollbar/rollbar-go"
)

func main() {
roll.Token = "POST_SERVER_ITEM_ACCESS_TOKEN"
//roll.Environment = "production" // defaults to "development"
roll.SetToken("MY_TOKEN")
// roll.SetEnvironment("production") // defaults to "development"

r := gin.Default()
r.Use(rollbar.Recovery(true))
Expand Down
7 changes: 4 additions & 3 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package main
import (
"github.com/gin-contrib/rollbar"
"github.com/gin-gonic/gin"
"github.com/stvp/roll"

roll "github.com/rollbar/rollbar-go"
)

func main() {
roll.Token = "POST_SERVER_ITEM_ACCESS_TOKEN"
//roll.Environment = "production" // defaults to "development"
roll.SetToken("MY_TOKEN")
// roll.SetEnvironment("production") // defaults to "development"

r := gin.Default()
r.Use(rollbar.Recovery(true))
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module github.com/gin-contrib/rollbar

go 1.13

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gin-gonic/gin v1.4.0
github.com/rollbar/rollbar-go v1.2.0
github.com/stretchr/testify v1.3.0
github.com/stvp/roll v0.0.0-20170522205222-3627a5cbeaea
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
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.2.0 h1:CUanFtVu0sa3QZ/fBlgevdGQGLWaE3D4HxoVSQohDfo=
github.com/rollbar/rollbar-go v1.2.0/go.mod h1:czC86b8U4xdUH7W2C6gomi2jutLm8qK0OtrF5WMvpcc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand Down
6 changes: 3 additions & 3 deletions recovey.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"runtime/debug"

"github.com/gin-gonic/gin"
"github.com/stvp/roll"
"github.com/rollbar/rollbar-go"
)

// Recovery middleware for rollbar error monitoring
Expand All @@ -20,15 +20,15 @@ func Recovery(onlyCrashes bool) gin.HandlerFunc {
if rval := recover(); rval != nil {
debug.PrintStack()

roll.CriticalStack(errors.New(fmt.Sprint(rval)), getCallers(3), map[string]string{
rollbar.Critical(errors.New(fmt.Sprint(rval)), getCallers(3), map[string]string{
"endpoint": c.Request.RequestURI})

c.AbortWithStatus(http.StatusInternalServerError)
}

if !onlyCrashes {
for _, item := range c.Errors {
roll.Error(item.Err, map[string]string{
rollbar.Error(item.Err, map[string]string{
"meta": fmt.Sprint(item.Meta),
"endpoint": c.Request.RequestURI,
})
Expand Down

0 comments on commit ca870f0

Please sign in to comment.