-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
76 lines (61 loc) · 1.31 KB
/
main.go
File metadata and controls
76 lines (61 loc) · 1.31 KB
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
73
74
75
76
package main
import (
"log"
"os"
"strings"
"time"
"github.com/getsentry/sentry-go"
"github.com/lambda-feedback/shimmy/cmd"
"github.com/lambda-feedback/shimmy/util"
)
var Version string
var Buildtime string
var Commit string
func main() {
err := setupSentry()
if err != nil {
log.Fatalf("sentry init failed: %s", err)
}
defer flushSentry()
appVersion := "local"
if Version != "" {
appVersion = Version
}
appBuildtime, _ := time.Parse(time.RFC3339, Buildtime)
cmd.Execute(cmd.ExecuteParams{
Version: appVersion,
Compiled: appBuildtime,
})
}
func setupSentry() error {
dsn := os.Getenv("SENTRY_DSN")
if dsn == "" {
return nil
}
environment := os.Getenv("SENTRY_ENVIRONMENT")
if environment == "" {
environment = "local"
}
var debug bool
sentryDebug := strings.ToLower(os.Getenv("SENTRY_DEBUG"))
if util.Truthy(sentryDebug) {
debug = true
}
err := sentry.Init(sentry.ClientOptions{
Dsn: dsn,
Debug: debug,
TracesSampleRate: 1.0,
EnableTracing: true,
Environment: environment,
Release: Commit,
})
if err != nil {
return err
}
return nil
}
func flushSentry() {
// Flush buffered events before the program terminates.
// Set the timeout to the maximum duration the program can afford to wait.
defer sentry.Flush(2 * time.Second)
}