package sentry

import (
	"errors"
	"fmt"
	"net/http"
	"runtime/debug"

	"github.com/getsentry/raven-go"
	"github.com/gin-gonic/gin"
)

func Recovery(client *raven.Client, onlyCrashes bool) gin.HandlerFunc {

	return func(c *gin.Context) {
		defer func() {
			flags := map[string]string{
				"endpoint": c.Request.RequestURI,
			}
			if rval := recover(); rval != nil {
				debug.PrintStack()
				rvalStr := fmt.Sprint(rval)
				packet := raven.NewPacket(rvalStr,
					raven.NewException(errors.New(rvalStr), raven.NewStacktrace(2, 3, nil)),
					raven.NewHttp(c.Request))
				client.Capture(packet, flags)
				c.AbortWithStatus(http.StatusInternalServerError)
			}
			if !onlyCrashes {
				for _, item := range c.Errors {
					packet := raven.NewPacket(item.Error(), &raven.Message{
						Message: item.Error(),
						Params:  []interface{}{item.Meta},
					})
					client.Capture(packet, flags)
				}
			}
		}()

		c.Next()
	}
}

package sentry

import (
	"errors"
	"fmt"
	"net/http"
	"runtime/debug"

	"github.com/getsentry/raven-go"
	"github.com/gin-gonic/gin"
)

func Recovery(client *raven.Client, onlyCrashes bool) gin.HandlerFunc {

	return func(c *gin.Context) {
		defer func() {
			flags := map[string]string{
				"endpoint": c.Request.RequestURI,
			}
			if rval := recover(); rval != nil {
				debug.PrintStack()
				rvalStr := fmt.Sprint(rval)
				packet := raven.NewPacket(rvalStr, raven.NewException(errors.New(rvalStr), raven.NewStacktrace(2, 3, nil)))
				client.Capture(packet, flags)
				c.AbortWithStatus(http.StatusInternalServerError)
			}
			if !onlyCrashes {
				for _, item := range c.Errors {
					packet := raven.NewPacket(item.Error(), &raven.Message{
						Message: item.Error(),
						Params:  []interface{}{item.Meta},
					})
					client.Capture(packet, flags)
				}
			}
		}()

		c.Next()
	}
}

--- 
+++ 
@@ -20,7 +20,9 @@
 			if rval := recover(); rval != nil {
 				debug.PrintStack()
 				rvalStr := fmt.Sprint(rval)
-				packet := raven.NewPacket(rvalStr, raven.NewException(errors.New(rvalStr), raven.NewStacktrace(2, 3, nil)))
+				packet := raven.NewPacket(rvalStr,
+					raven.NewException(errors.New(rvalStr), raven.NewStacktrace(2, 3, nil)),
+					raven.NewHttp(c.Request))
 				client.Capture(packet, flags)
 				c.AbortWithStatus(http.StatusInternalServerError)
 			}
Add NewHttp to the list of captured interfaces

This adds some nice error reporting info like IP address, cookies, headers, etc.

See https://github.com/getsentry/raven-go/blob/master/http.go#L76
