/
payload.go
81 lines (71 loc) · 2.27 KB
/
payload.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
package sessions
import (
"runtime"
"time"
"github.com/bugsnag/bugsnag-go/device"
)
// notifierPayload defines the .notifier subobject of the payload
type notifierPayload struct {
Name string `json:"name"`
URL string `json:"url"`
Version string `json:"version"`
}
// appPayload defines the .app subobject of the payload
type appPayload struct {
Type string `json:"type,omitempty"`
ReleaseStage string `json:"releaseStage,omitempty"`
Version string `json:"version,omitempty"`
}
// devicePayload defines the .device subobject of the payload
type devicePayload struct {
OsName string `json:"osName,omitempty"`
Hostname string `json:"hostname,omitempty"`
RuntimeVersions *device.RuntimeVersions `json:"runtimeVersions"`
}
// sessionCountsPayload defines the .sessionCounts subobject of the payload
type sessionCountsPayload struct {
StartedAt string `json:"startedAt"`
SessionsStarted int `json:"sessionsStarted"`
}
// sessionPayload defines the top level payload object
type sessionPayload struct {
Notifier *notifierPayload `json:"notifier"`
App *appPayload `json:"app"`
Device *devicePayload `json:"device"`
SessionCounts []sessionCountsPayload `json:"sessionCounts"`
}
// makeSessionPayload creates a sessionPayload based off of the given sessions and config
func makeSessionPayload(sessions []*Session, config *SessionTrackingConfiguration) *sessionPayload {
releaseStage := config.ReleaseStage
if releaseStage == "" {
releaseStage = "production"
}
hostname := config.Hostname
if hostname == "" {
hostname = device.GetHostname()
}
return &sessionPayload{
Notifier: ¬ifierPayload{
Name: "Bugsnag Go",
URL: "https://github.com/bugsnag/bugsnag-go",
Version: config.Version,
},
App: &appPayload{
Type: config.AppType,
Version: config.AppVersion,
ReleaseStage: releaseStage,
},
Device: &devicePayload{
OsName: runtime.GOOS,
Hostname: hostname,
RuntimeVersions: device.GetRuntimeVersions(),
},
SessionCounts: []sessionCountsPayload{
{
//This timestamp assumes that we're sending these off once a minute
StartedAt: sessions[0].StartedAt.UTC().Format(time.RFC3339),
SessionsStarted: len(sessions),
},
},
}
}