forked from honeycombio/refinery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.go
95 lines (78 loc) · 2.15 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
package types
import (
"context"
"time"
)
const (
APIKeyHeader = "X-Honeycomb-Team"
// libhoney-js uses this
APIKeyHeaderShort = "X-Hny-Team"
DatasetHeader = "X-Honeycomb-Dataset"
SampleRateHeader = "X-Honeycomb-Samplerate"
TimestampHeader = "X-Honeycomb-Event-Time"
QueryTokenHeader = "X-Honeycomb-Refinery-Query"
)
// used to put a request ID into the request context for logging
type RequestIDContextKey struct{}
// event is not part of a trace - it's an event that showed up with no trace ID
type Event struct {
Context context.Context
APIHost string
APIKey string
Dataset string
Environment string
SampleRate uint
Timestamp time.Time
Data map[string]interface{}
}
// Trace isn't something that shows up on the wire; it gets created within
// Refinery. Traces are not thread-safe; only one goroutine should be working
// with a trace object at a time.
type Trace struct {
APIHost string
APIKey string
Dataset string
TraceID string
// SampleRate should only be changed if the changer holds the SendSampleLock
SampleRate uint
// KeepSample should only be changed if the changer holds the SendSampleLock
KeepSample bool
// Sent should only be changed if the changer holds the SendSampleLock
Sent bool
SendBy time.Time
// StartTime is the server time when the first span arrived for this trace.
// Used to calculate how long traces spend sitting in Refinery
StartTime time.Time
HasRootSpan bool
// spans is the list of spans in this trace
spans []*Span
}
// AddSpan adds a span to this trace
func (t *Trace) AddSpan(sp *Span) {
t.spans = append(t.spans, sp)
}
// GetSpans returns the list of spans in this trace
func (t *Trace) GetSpans() []*Span {
return t.spans
}
func (t *Trace) GetSamplerKey() (string, bool) {
if IsLegacyAPIKey(t.APIKey) {
return t.Dataset, true
}
env := ""
for _, sp := range t.GetSpans() {
if sp.Event.Environment != "" {
env = sp.Event.Environment
break
}
}
return env, false
}
// Span is an event that shows up with a trace ID, so will be part of a Trace
type Span struct {
Event
TraceID string
}
func IsLegacyAPIKey(apiKey string) bool {
return len(apiKey) == 32
}