-
Notifications
You must be signed in to change notification settings - Fork 4
/
workflow.go
123 lines (103 loc) · 2.88 KB
/
workflow.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package sentrytemporal
import (
"github.com/getsentry/sentry-go"
"go.temporal.io/sdk/interceptor"
"go.temporal.io/sdk/temporal"
"go.temporal.io/sdk/workflow"
)
type workflowInboundInterceptor struct {
interceptor.WorkflowInboundInterceptorBase
root *workerInterceptor
}
// ExecuteWorkflow implements WorkflowInboundInterceptor.ExecuteWorkflow.
func (w *workflowInboundInterceptor) ExecuteWorkflow(
ctx workflow.Context,
in *interceptor.ExecuteWorkflowInput,
) (ret interface{}, err error) {
configureScope := func(scope *sentry.Scope) {
info := workflow.GetInfo(ctx)
scope.SetContext("workflow info", mustStruct2Map(info))
scope.SetContext("execute workflow input", mustStruct2Map(in))
scope.SetTag("temporal_io_kind", "ExecuteWorkflow")
scope.SetFingerprint(
[]string{
info.TaskQueueName,
info.WorkflowType.Name,
"{{ default }}",
},
)
if w.root.options.WorkflowScopeCustomizer != nil {
w.root.options.WorkflowScopeCustomizer(ctx, scope, err)
}
}
defer func() {
if x := recover(); x != nil {
hub := sentry.CurrentHub().Clone()
hub.ConfigureScope(configureScope)
hub.ConfigureScope(func(scope *sentry.Scope) {
scope.SetLevel(sentry.LevelFatal)
})
_ = hub.Recover(x)
panic(x)
}
}()
ret, err = w.Next.ExecuteWorkflow(ctx, in)
if err != nil {
if isContinueAsNewError(err) {
return
}
if temporal.IsCanceledError(err) || temporal.IsTimeoutError(err) || temporal.IsTerminatedError(err) {
return
}
if skipper := w.root.options.WorkflowErrorSkipper; skipper != nil && skipper(ctx, err) {
return
}
hub := sentry.CurrentHub().Clone()
hub.ConfigureScope(configureScope)
_ = hub.CaptureException(err)
}
return
}
// HandleQuery implements WorkflowInboundInterceptor.HandleQuery.
func (w *workflowInboundInterceptor) HandleQuery(
ctx workflow.Context,
in *interceptor.HandleQueryInput,
) (ret interface{}, err error) {
configureScope := func(scope *sentry.Scope) {
info := workflow.GetInfo(ctx)
scope.SetContext("workflow info", mustStruct2Map(info))
scope.SetContext("handle query input", mustStruct2Map(in))
scope.SetTag("temporal_io_kind", "HandleQuery")
scope.SetFingerprint(
[]string{
info.TaskQueueName,
info.WorkflowType.Name,
"{{ default }}",
},
)
}
defer func() {
if x := recover(); x != nil {
hub := w.root.hub.Clone()
hub.ConfigureScope(configureScope)
hub.ConfigureScope(func(scope *sentry.Scope) {
scope.SetLevel(sentry.LevelFatal)
})
_ = hub.Recover(x)
panic(x)
}
}()
ret, err = w.Next.HandleQuery(ctx, in)
if err != nil {
if temporal.IsCanceledError(err) || temporal.IsTimeoutError(err) || temporal.IsTerminatedError(err) {
return
}
if skipper := w.root.options.WorkflowErrorSkipper; skipper != nil && skipper(ctx, err) {
return
}
hub := w.root.hub.Clone()
hub.ConfigureScope(configureScope)
_ = hub.CaptureException(err)
}
return
}