File: main.go

package info (click to toggle)
golang-github-getsentry-sentry-go 0.29.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,404 kB
  • sloc: makefile: 75; sh: 21
file content (72 lines) | stat: -rw-r--r-- 1,080 bytes parent folder | download
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main

import (
	"encoding/json"
	"errors"
	"fmt"
	"time"

	"github.com/getsentry/sentry-go"
)

func prettyPrint(v interface{}) string {
	pp, _ := json.MarshalIndent(v, "", "  ")
	return string(pp)
}

func fooErr() {
	barErr()
}

func barErr() {
	bazErr()
}

func bazErr() {
	panic(errors.New("sorry with error :("))
}

func fooMsg() {
	barMsg()
}

func barMsg() {
	bazMsg()
}

func bazMsg() {
	panic("sorry with message :(")
}

func main() {
	_ = sentry.Init(sentry.ClientOptions{
		Debug:            true,
		Dsn:              "https://hello@example.com/1337",
		AttachStacktrace: true,
		BeforeSend: func(e *sentry.Event, h *sentry.EventHint) *sentry.Event {
			fmt.Println(prettyPrint(e))
			return e
		},
	})

	sentry.ConfigureScope(func(scope *sentry.Scope) {
		scope.SetExtra("oristhis", "justfantasy")
		scope.SetTag("isthis", "reallife")
		scope.SetLevel(sentry.LevelFatal)
		scope.SetUser(sentry.User{
			ID: "1337",
		})
	})

	func() {
		defer sentry.Recover()
		fooErr()
	}()

	func() {
		defer sentry.Recover()
		fooMsg()
	}()

	sentry.Flush(time.Second * 5)
}