-
Notifications
You must be signed in to change notification settings - Fork 4
/
worker.go
71 lines (57 loc) · 1.95 KB
/
worker.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
package sentrytemporal
import (
"context"
"github.com/getsentry/sentry-go"
"go.temporal.io/sdk/interceptor"
"go.temporal.io/sdk/workflow"
)
type Options struct {
// ActivityErrorSkipper configures a function to determine if an error from activity should be skipped.
// If it returns true, the error is ignored.
ActivityErrorSkipper ActivityErrorSkipper
// WorkflowErrorSkipper configures a function to determine if an error from workflow should be skipped.
// If it returns true, the error is ignored.
WorkflowErrorSkipper WorkflowErrorSkipper
// ActivityScopeCustomizer applies custom options to a sentry.Scope just before an error is reported from an activity
ActivityScopeCustomizer ActivityScopeCustomizer
// WorkflowScopeCustomizer applies custom options to a sentry.Scope just before an error is reported from a workflow
WorkflowScopeCustomizer WorkflowScopeCustomizer
}
type (
ActivityErrorSkipper func(context.Context, error) bool
WorkflowErrorSkipper func(workflow.Context, error) bool
ActivityScopeCustomizer func(context.Context, *sentry.Scope, error)
WorkflowScopeCustomizer func(workflow.Context, *sentry.Scope, error)
)
// New creates a worker interceptor which will report error to sentry.
func New(hub *sentry.Hub, opts Options) interceptor.WorkerInterceptor {
i := &workerInterceptor{
options: opts,
hub: hub,
}
if i.hub == nil {
i.hub = sentry.CurrentHub()
}
return i
}
type workerInterceptor struct {
interceptor.WorkerInterceptorBase
options Options
hub *sentry.Hub
}
func (w *workerInterceptor) InterceptActivity(
ctx context.Context,
next interceptor.ActivityInboundInterceptor,
) interceptor.ActivityInboundInterceptor {
i := &activityInboundInterceptor{root: w}
i.Next = next
return i
}
func (w *workerInterceptor) InterceptWorkflow(
ctx workflow.Context,
next interceptor.WorkflowInboundInterceptor,
) interceptor.WorkflowInboundInterceptor {
i := &workflowInboundInterceptor{root: w}
i.Next = next
return i
}