-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapollo_tracing.go
62 lines (54 loc) · 1.51 KB
/
apollo_tracing.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 yarql
import (
"encoding/json"
"time"
)
type tracer struct {
Version uint8 `json:"version"`
GoStartTime time.Time `json:"-"`
StartTime string `json:"startTime"`
EndTime string `json:"endTime"`
Duration int64 `json:"duration"`
Parsing tracerStartAndDuration `json:"parsing"`
Validation tracerStartAndDuration `json:"validation"`
Execution tracerExecution `json:"execution"`
}
type tracerStartAndDuration struct {
StartOffset int64 `json:"startOffset"`
Duration int64 `json:"duration"`
}
type tracerExecution struct {
Resolvers []tracerResolver `json:"resolvers"`
}
type tracerResolver struct {
Path json.RawMessage `json:"path"`
ParentType string `json:"parentType"`
FieldName string `json:"fieldName"`
ReturnType string `json:"returnType"`
StartOffset int64 `json:"startOffset"`
Duration int64 `json:"duration"`
}
func newTracer() *tracer {
return &tracer{
Version: 1,
GoStartTime: time.Now(),
Execution: tracerExecution{
Resolvers: []tracerResolver{},
},
}
}
func (t *tracer) reset() {
*t = tracer{
Version: 1,
GoStartTime: time.Now(),
Execution: tracerExecution{
Resolvers: t.Execution.Resolvers[:0],
},
}
}
func (t *tracer) finish() {
t.StartTime = t.GoStartTime.Format(time.RFC3339Nano)
now := time.Now()
t.EndTime = now.Format(time.RFC3339Nano)
t.Duration = now.Sub(t.GoStartTime).Nanoseconds()
}