-
Notifications
You must be signed in to change notification settings - Fork 10
/
fileuploadermetrics.go
78 lines (63 loc) · 3.06 KB
/
fileuploadermetrics.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 FileUploader -t opentelemetry.template -o fileuploadermetrics.go
import (
"context"
"time"
"unicode"
"github.com/slack-go/slack"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric"
)
// FileUploaderWithTelemetry implements FileUploader interface with all methods wrapped
// with open telemetry metrics
type FileUploaderWithTelemetry struct {
base FileUploader
methodCounters map[string]metric.BoundInt64Counter
errCounters map[string]metric.BoundInt64Counter
methodTimeValueRecorders map[string]metric.BoundInt64ValueRecorder
}
// NewFileUploaderWithTelemetry returns an instance of the FileUploader decorated with open telemetry timing and count metrics
func NewFileUploaderWithTelemetry(base FileUploader, name string, meter metric.Meter) FileUploaderWithTelemetry {
return FileUploaderWithTelemetry{
base: base,
methodCounters: newFileUploaderMethodCounters("Calls", name, meter),
errCounters: newFileUploaderMethodCounters("Errors", name, meter),
methodTimeValueRecorders: newFileUploaderMethodTimeValueRecorders(name, meter),
}
}
func newFileUploaderMethodTimeValueRecorders(appName string, meter metric.Meter) (boundTimeValueRecorders map[string]metric.BoundInt64ValueRecorder) {
boundTimeValueRecorders = make(map[string]metric.BoundInt64ValueRecorder)
mt := metric.Must(meter)
nUploadFileValRecorder := []rune("FileUploader_UploadFile_ProcessingTimeMillis")
nUploadFileValRecorder[0] = unicode.ToLower(nUploadFileValRecorder[0])
mUploadFile := mt.NewInt64ValueRecorder(string(nUploadFileValRecorder))
boundTimeValueRecorders["UploadFile"] = mUploadFile.Bind(label.String("name", appName))
return boundTimeValueRecorders
}
func newFileUploaderMethodCounters(suffix string, appName string, meter metric.Meter) (boundCounters map[string]metric.BoundInt64Counter) {
boundCounters = make(map[string]metric.BoundInt64Counter)
mt := metric.Must(meter)
nUploadFileCounter := []rune("FileUploader_UploadFile_" suffix)
nUploadFileCounter[0] = unicode.ToLower(nUploadFileCounter[0])
cUploadFile := mt.NewInt64Counter(string(nUploadFileCounter))
boundCounters["UploadFile"] = cUploadFile.Bind(label.String("name", appName))
return boundCounters
}
// UploadFile implements FileUploader
func (_d FileUploaderWithTelemetry) UploadFile(params slack.FileUploadParameters, options ...UploadOption) (file *slack.File, err error) {
_since := time.Now()
defer func() {
if err != nil {
errCounter := _d.errCounters["UploadFile"]
errCounter.Add(context.Background(), 1)
}
methodCounter := _d.methodCounters["UploadFile"]
methodCounter.Add(context.Background(), 1)
methodTimeMeasure := _d.methodTimeValueRecorders["UploadFile"]
methodTimeMeasure.Record(context.Background(), time.Since(_since).Milliseconds())
}()
return _d.base.UploadFile(params, options...)
}