forked from pinpoint-apm/pinpoint-go-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
span_event.go
104 lines (87 loc) · 2.1 KB
/
span_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
package pinpoint
import (
"time"
)
type spanEvent struct {
parentSpan *span
serviceType int32
sequence int32
depth int32
startTime time.Time
startElapsed time.Duration
duration time.Duration
operationName string
nextSpanId int64
annotations annotation
endPoint string
destinationId string
errorFuncId int32
errorString string
asyncId int32
asyncSeqGen int32
apiId int32
isTimeFixed bool
}
func newSpanEvent(span *span, operationName string) *spanEvent {
se := spanEvent{}
se.parentSpan = span
se.startTime = time.Now()
se.startElapsed = se.startTime.Sub(span.startTime)
se.sequence = span.eventSequence
se.depth = span.eventDepth
se.operationName = operationName
se.endPoint = ""
se.asyncId = 0
se.asyncSeqGen = 0
se.serviceType = ServiceTypeGoFunction
se.isTimeFixed = false
return &se
}
func (se *spanEvent) end() {
se.parentSpan.eventDepth--
if !se.isTimeFixed {
se.duration = time.Now().Sub(se.startTime)
}
}
func (se *spanEvent) generateNextSpanId() int64 {
se.nextSpanId = generateSpanId()
return se.nextSpanId
}
func (se *spanEvent) SetError(e error) {
if e == nil {
return
}
id := se.parentSpan.agent.cacheErrorFunc(se.operationName)
se.errorFuncId = id
se.errorString = e.Error()
}
func (se *spanEvent) SetApiId(id int32) {
se.apiId = id
}
func (se *spanEvent) SetServiceType(typ int32) {
se.serviceType = typ
}
func (se *spanEvent) SetDestination(id string) {
se.destinationId = id
}
func (se *spanEvent) SetEndPoint(endPoint string) {
se.endPoint = endPoint
}
func (se *spanEvent) SetSQL(sql string) {
if sql == "" {
return
}
normalizer := newSqlNormalizer(sql)
nsql, param := normalizer.run()
id := se.parentSpan.agent.cacheSql(nsql)
se.annotations.AppendIntStringString(20, id, param, "" /* bind value for prepared stmt */)
}
func (span *spanEvent) Annotations() Annotation {
return &span.annotations
}
func (se *spanEvent) FixDuration(start time.Time, end time.Time) {
se.startTime = start
se.startElapsed = start.Sub(se.parentSpan.startTime)
se.duration = end.Sub(start)
se.isTimeFixed = true
}