-
Notifications
You must be signed in to change notification settings - Fork 129
/
goflow_event_handler.go
91 lines (71 loc) · 2.49 KB
/
goflow_event_handler.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
package eventhandler
import (
"fmt"
"github.com/s8sg/goflow/core/sdk"
)
// implements core.EventHandler
type GoFlowEventHandler struct {
CurrentNodeID string // used to inject current node id in Tracer
Tracer *TraceHandler // handle traces with open-tracing
flowName string
TraceURI string
Header map[string][]string
}
func (eh *GoFlowEventHandler) Configure(flowName string, requestID string) {
eh.flowName = flowName
}
func (eh *GoFlowEventHandler) Init() error {
var err error
// initialize trace server if tracing enabled
eh.Tracer, err = initRequestTracer(eh.flowName, eh.TraceURI)
if err != nil {
return fmt.Errorf("failed to init request Tracer, error %v", err)
}
return nil
}
func (eh *GoFlowEventHandler) Copy() (sdk.EventHandler, error) {
newHandler := &GoFlowEventHandler{}
newHandler.TraceURI = eh.TraceURI
newHandler.CurrentNodeID = eh.CurrentNodeID
newHandler.Header = eh.Header
return newHandler, nil
}
func (eh *GoFlowEventHandler) ReportRequestStart(requestID string) {
eh.Tracer.StartReqSpan(requestID)
}
func (eh *GoFlowEventHandler) ReportRequestFailure(requestID string, err error) {
// TODO: add log
eh.Tracer.StopReqSpan()
}
func (eh *GoFlowEventHandler) ReportExecutionForward(currentNodeID string, requestID string) {
eh.CurrentNodeID = currentNodeID
}
func (eh *GoFlowEventHandler) ReportExecutionContinuation(requestID string) {
eh.Tracer.ContinueReqSpan(requestID, eh.Header)
}
func (eh *GoFlowEventHandler) ReportRequestEnd(requestID string) {
eh.Tracer.StopReqSpan()
}
func (eh *GoFlowEventHandler) ReportNodeStart(nodeID string, requestID string) {
eh.Tracer.StartNodeSpan(nodeID, requestID)
}
func (eh *GoFlowEventHandler) ReportNodeEnd(nodeID string, requestID string) {
eh.Tracer.StopNodeSpan(nodeID)
}
func (eh *GoFlowEventHandler) ReportNodeFailure(nodeID string, requestID string, err error) {
// TODO: add log
eh.Tracer.StopNodeSpan(nodeID)
}
func (eh *GoFlowEventHandler) ReportOperationStart(operationID string, nodeID string, requestID string) {
eh.Tracer.StartOperationSpan(nodeID, requestID, operationID)
}
func (eh *GoFlowEventHandler) ReportOperationEnd(operationID string, nodeID string, requestID string) {
eh.Tracer.StopOperationSpan(nodeID, operationID)
}
func (eh *GoFlowEventHandler) ReportOperationFailure(operationID string, nodeID string, requestID string, err error) {
// TODO: add log
eh.Tracer.StopOperationSpan(nodeID, operationID)
}
func (eh *GoFlowEventHandler) Flush() {
eh.Tracer.FlushTracer()
}