-
Notifications
You must be signed in to change notification settings - Fork 10
/
userinfofindermetrics.go
78 lines (63 loc) · 3.07 KB
/
userinfofindermetrics.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
package slackscot
// DO NOT EDIT!
// This code is generated with http://github.com/hexdigest/gowrap tool
// using opentelemetry.template template
//go:generate gowrap gen -p github.com/alexandre-normand/slackscot -i UserInfoFinder -t opentelemetry.template -o userinfofindermetrics.go
import (
"context"
"time"
"unicode"
"github.com/slack-go/slack"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric"
)
// UserInfoFinderWithTelemetry implements UserInfoFinder interface with all methods wrapped
// with open telemetry metrics
type UserInfoFinderWithTelemetry struct {
base UserInfoFinder
methodCounters map[string]metric.BoundInt64Counter
errCounters map[string]metric.BoundInt64Counter
methodTimeValueRecorders map[string]metric.BoundInt64ValueRecorder
}
// NewUserInfoFinderWithTelemetry returns an instance of the UserInfoFinder decorated with open telemetry timing and count metrics
func NewUserInfoFinderWithTelemetry(base UserInfoFinder, name string, meter metric.Meter) UserInfoFinderWithTelemetry {
return UserInfoFinderWithTelemetry{
base: base,
methodCounters: newUserInfoFinderMethodCounters("Calls", name, meter),
errCounters: newUserInfoFinderMethodCounters("Errors", name, meter),
methodTimeValueRecorders: newUserInfoFinderMethodTimeValueRecorders(name, meter),
}
}
func newUserInfoFinderMethodTimeValueRecorders(appName string, meter metric.Meter) (boundTimeValueRecorders map[string]metric.BoundInt64ValueRecorder) {
boundTimeValueRecorders = make(map[string]metric.BoundInt64ValueRecorder)
mt := metric.Must(meter)
nGetUserInfoValRecorder := []rune("UserInfoFinder_GetUserInfo_ProcessingTimeMillis")
nGetUserInfoValRecorder[0] = unicode.ToLower(nGetUserInfoValRecorder[0])
mGetUserInfo := mt.NewInt64ValueRecorder(string(nGetUserInfoValRecorder))
boundTimeValueRecorders["GetUserInfo"] = mGetUserInfo.Bind(label.String("name", appName))
return boundTimeValueRecorders
}
func newUserInfoFinderMethodCounters(suffix string, appName string, meter metric.Meter) (boundCounters map[string]metric.BoundInt64Counter) {
boundCounters = make(map[string]metric.BoundInt64Counter)
mt := metric.Must(meter)
nGetUserInfoCounter := []rune("UserInfoFinder_GetUserInfo_" + suffix)
nGetUserInfoCounter[0] = unicode.ToLower(nGetUserInfoCounter[0])
cGetUserInfo := mt.NewInt64Counter(string(nGetUserInfoCounter))
boundCounters["GetUserInfo"] = cGetUserInfo.Bind(label.String("name", appName))
return boundCounters
}
// GetUserInfo implements UserInfoFinder
func (_d UserInfoFinderWithTelemetry) GetUserInfo(userID string) (user *slack.User, err error) {
_since := time.Now()
defer func() {
if err != nil {
errCounter := _d.errCounters["GetUserInfo"]
errCounter.Add(context.Background(), 1)
}
methodCounter := _d.methodCounters["GetUserInfo"]
methodCounter.Add(context.Background(), 1)
methodTimeMeasure := _d.methodTimeValueRecorders["GetUserInfo"]
methodTimeMeasure.Record(context.Background(), time.Since(_since).Milliseconds())
}()
return _d.base.GetUserInfo(userID)
}