-
Notifications
You must be signed in to change notification settings - Fork 3
/
event.go
120 lines (110 loc) · 2.92 KB
/
event.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"encoding/json"
"errors"
"fmt"
"log"
"github.com/getsentry/sentry-go"
)
type TypeSwitch struct {
Kind string `json:"type"`
}
type Event struct {
TypeSwitch `json:"type"`
Platform string
*Error
*Transaction
*DSN
}
const DEFAULT = "default"
func (event *Event) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &event.TypeSwitch); err != nil {
return err
}
// may not need
if event.Kind == "" {
fmt.Println("> event.Kind", event.Kind)
sentry.CaptureMessage("no event.Kind set")
log.Fatal("no event.Kind set")
}
switch event.Kind {
case ERROR:
event.Error = &Error{}
return json.Unmarshal(data, event.Error)
case TRANSACTION:
event.Transaction = &Transaction{}
return json.Unmarshal(data, event.Transaction)
case DEFAULT:
event.Error = &Error{}
return json.Unmarshal(data, event.Error)
default:
sentry.CaptureMessage("unrecognized type value " + event.Kind)
return fmt.Errorf("unrecognized type value %q", event.Kind)
}
}
func (event *Event) getPlatform() string {
var platform string
if event.Kind == TRANSACTION {
platform = event.Transaction.Platform
}
if event.Kind == ERROR {
platform = event.Error.Platform
}
if event.Kind == DEFAULT {
platform = event.Error.Platform
}
if platform == "" {
sentry.CaptureException(errors.New("no event platform set"))
log.Fatalf("no event platform set")
}
return platform
}
func (event *Event) setDsn(dsn string) {
event.DSN = NewDSN(dsn)
if event.DSN == nil {
sentry.CaptureException(errors.New("null DSN"))
log.Fatal("null DSN")
}
}
func (event *Event) setPlatform() {
for _, platform := range platforms {
if (event.Kind == ERROR || event.Kind == DEFAULT) && event.Error.Platform == platform {
event.Platform = platform
break
} else if event.Kind == TRANSACTION && event.Transaction.Platform == platform {
event.Platform = platform
break
}
}
if event.Platform == "" {
sentry.CaptureException(errors.New("event.Kind and Platform condition not found" + event.Kind))
// log.Fatalf("event Kind: %v and Platform: %v not recognized", event.Kind, event.Platform)
}
}
// Undertaker adds the demo-automation tag
func (e Event) undertake() {
if e.Kind == ERROR || e.Kind == DEFAULT {
if e.Error.Tags == nil {
e.Error.Tags = make([][]string, 0)
}
// Some of the event files in CloudStorage have a tag:value of 'demo-automation:replay'
// which has been deprecated in favor of 'se:replay'
// TODO update files in CloudStorage to not have demo-automation tag, so can simplify the below code
demoAutomation := false
for _, tag := range e.Error.Tags {
if tag[0] == "demo-automation" {
tag[0] = "se" // and value is already "replay"
demoAutomation = true
}
}
if demoAutomation == false {
tag := []string{"se", "replay"}
e.Error.Tags = append(e.Error.Tags, tag)
}
}
if e.Kind == TRANSACTION {
if e.Transaction.Tags == nil {
e.Transaction.Tags = make([][]string, 0)
}
}
}