/
main.go
55 lines (45 loc) · 1.43 KB
/
main.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
package main
import (
"fmt"
"net/http"
sentrymartini "github.com/getsentry/sentry-go/martini"
"github.com/getsentry/sentry-go"
"github.com/go-martini/martini"
)
func main() {
_ = sentry.Init(sentry.ClientOptions{
Dsn: "https://363a337c11a64611be4845ad6e24f3ac@sentry.io/297378",
BeforeSend: func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event {
if hint.Context != nil {
if req, ok := hint.Context.Value(sentry.RequestContextKey).(*http.Request); ok {
// You have access to the original Request
fmt.Println(req)
}
}
fmt.Println(event)
return event
},
Debug: true,
AttachStacktrace: true,
})
app := martini.Classic()
app.Use(sentrymartini.New(sentrymartini.Options{
Repanic: true,
}))
app.Use(func(rw http.ResponseWriter, r *http.Request, c martini.Context, hub *sentry.Hub) {
hub.Scope().SetTag("someRandomTag", "maybeYouNeedIt")
})
app.Get("/", func(rw http.ResponseWriter, r *http.Request, hub *sentry.Hub) {
hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("unwantedQuery", "someQueryDataMaybe")
hub.CaptureMessage("User provided unwanted query string, but we recovered just fine")
})
rw.WriteHeader(http.StatusOK)
})
app.Get("/foo", func() string {
// sentrymartini handler will catch it just fine, and because we attached "someRandomTag"
// in the middleware before, it will be sent through as well
panic("y tho")
})
app.RunOnAddr(":3000")
}