/
event.go
62 lines (55 loc) · 1.89 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
package activity
import (
"encoding/json"
"time"
)
// Event is a telemetry event. It consists of a few required fields that are common to all events and a payload of type-specific data.
// All the common fields are prefixed with "event_" to avoid conflicts with the payload data.
type Event struct {
EventID string
EventTime time.Time
EventType string
EventName string
Data map[string]any
}
func (e Event) MarshalJSON() ([]byte, error) {
// Add the common fields to the map.
if e.Data == nil {
e.Data = make(map[string]any)
}
e.Data["event_id"] = e.EventID
e.Data["event_time"] = e.EventTime.UTC().Format(time.RFC3339Nano)
e.Data["event_type"] = e.EventType
e.Data["event_name"] = e.EventName
// Then serialize it.
return json.Marshal(e.Data)
}
// Constants for common event types.
const (
EventTypeLog = "log"
EventTypeMetric = "metric"
EventTypeBehavioral = "behavioral"
)
// Constants for common event attribute keys.
const (
AttrKeyServiceName = "service_name"
AttrKeyServiceVersion = "service_version"
AttrKeyServiceCommit = "service_commit"
AttrKeyIsDev = "is_dev"
AttrKeyInstallID = "install_id"
AttrKeyUserID = "user_id"
)
// Constants for event names of type EventTypeBehavioral.
// Note: This list is not exhaustive. Proxied events may contain other names.
const (
BehavioralEventInstallSuccess = "install-success"
BehavioralEventAppStart = "app-start"
BehavioralEventLoginStart = "login-start"
BehavioralEventLoginSuccess = "login-success"
BehavioralEventDeployStart = "deploy-start"
BehavioralEventDeploySuccess = "deploy-success"
BehavioralEventGithubConnectedStart = "ghconnected-start"
BehavioralEventGithubConnectedSuccess = "ghconnected-success"
BehavioralEventDataAccessStart = "dataaccess-start"
BehavioralEventDataAccessSuccess = "dataaccess-success"
)