-
-
Notifications
You must be signed in to change notification settings - Fork 606
/
metrics.go
158 lines (129 loc) · 3.62 KB
/
metrics.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package metrics
import (
"context"
"net/http"
"github.com/imgproxy/imgproxy/v3/metrics/cloudwatch"
"github.com/imgproxy/imgproxy/v3/metrics/datadog"
"github.com/imgproxy/imgproxy/v3/metrics/newrelic"
"github.com/imgproxy/imgproxy/v3/metrics/otel"
"github.com/imgproxy/imgproxy/v3/metrics/prometheus"
)
func Init() error {
prometheus.Init()
if err := newrelic.Init(); err != nil {
return nil
}
datadog.Init()
if err := otel.Init(); err != nil {
return err
}
if err := cloudwatch.Init(); err != nil {
return err
}
return nil
}
func Stop() {
newrelic.Stop()
datadog.Stop()
otel.Stop()
cloudwatch.Stop()
}
func Enabled() bool {
return prometheus.Enabled() ||
newrelic.Enabled() ||
datadog.Enabled() ||
otel.Enabled() ||
cloudwatch.Enabled()
}
func StartRequest(ctx context.Context, rw http.ResponseWriter, r *http.Request) (context.Context, context.CancelFunc, http.ResponseWriter) {
promCancel, rw := prometheus.StartRequest(rw)
ctx, nrCancel, rw := newrelic.StartTransaction(ctx, rw, r)
ctx, ddCancel, rw := datadog.StartRootSpan(ctx, rw, r)
ctx, otelCancel, rw := otel.StartRootSpan(ctx, rw, r)
cancel := func() {
promCancel()
nrCancel()
ddCancel()
otelCancel()
}
return ctx, cancel, rw
}
func StartQueueSegment(ctx context.Context) context.CancelFunc {
promCancel := prometheus.StartQueueSegment()
nrCancel := newrelic.StartSegment(ctx, "Queue")
ddCancel := datadog.StartSpan(ctx, "queue")
otelCancel := otel.StartSpan(ctx, "queue")
cancel := func() {
promCancel()
nrCancel()
ddCancel()
otelCancel()
}
return cancel
}
func StartDownloadingSegment(ctx context.Context) context.CancelFunc {
promCancel := prometheus.StartDownloadingSegment()
nrCancel := newrelic.StartSegment(ctx, "Downloading image")
ddCancel := datadog.StartSpan(ctx, "downloading_image")
otelCancel := otel.StartSpan(ctx, "downloading_image")
cancel := func() {
promCancel()
nrCancel()
ddCancel()
otelCancel()
}
return cancel
}
func StartProcessingSegment(ctx context.Context) context.CancelFunc {
promCancel := prometheus.StartProcessingSegment()
nrCancel := newrelic.StartSegment(ctx, "Processing image")
ddCancel := datadog.StartSpan(ctx, "processing_image")
otelCancel := otel.StartSpan(ctx, "processing_image")
cancel := func() {
promCancel()
nrCancel()
ddCancel()
otelCancel()
}
return cancel
}
func StartStreamingSegment(ctx context.Context) context.CancelFunc {
promCancel := prometheus.StartStreamingSegment()
nrCancel := newrelic.StartSegment(ctx, "Streaming image")
ddCancel := datadog.StartSpan(ctx, "streaming_image")
otelCancel := otel.StartSpan(ctx, "streaming_image")
cancel := func() {
promCancel()
nrCancel()
ddCancel()
otelCancel()
}
return cancel
}
func SendError(ctx context.Context, errType string, err error) {
prometheus.IncrementErrorsTotal(errType)
newrelic.SendError(ctx, errType, err)
datadog.SendError(ctx, errType, err)
otel.SendError(ctx, errType, err)
}
func ObserveBufferSize(t string, size int) {
prometheus.ObserveBufferSize(t, size)
newrelic.ObserveBufferSize(t, size)
datadog.ObserveBufferSize(t, size)
otel.ObserveBufferSize(t, size)
cloudwatch.ObserveBufferSize(t, size)
}
func SetBufferDefaultSize(t string, size int) {
prometheus.SetBufferDefaultSize(t, size)
newrelic.SetBufferDefaultSize(t, size)
datadog.SetBufferDefaultSize(t, size)
otel.SetBufferDefaultSize(t, size)
cloudwatch.SetBufferDefaultSize(t, size)
}
func SetBufferMaxSize(t string, size int) {
prometheus.SetBufferMaxSize(t, size)
newrelic.SetBufferMaxSize(t, size)
datadog.SetBufferMaxSize(t, size)
otel.SetBufferMaxSize(t, size)
cloudwatch.SetBufferMaxSize(t, size)
}