@@ -28,22 +28,6 @@ import (
28
28
// magicString is used for the hacky label test in checkLabels. Remove once fixed.
29
29
const magicString = "zZgWfBxLqvG8kc8IMv3POi2Bb0tZI3vAnBx+gBaFi9FyPzB/CzKUer1yufDa"
30
30
31
- // observeWithExemplar is a wrapper for [prometheus.ExemplarAdder.ExemplarObserver],
32
- // which falls back to [prometheus.Observer.Observe] if no labels are provided.
33
- func observeWithExemplar (obs prometheus.Observer , val float64 , labels map [string ]string ) {
34
- obs .(prometheus.ExemplarObserver ).ObserveWithExemplar (val , labels )
35
- }
36
-
37
- // addWithExemplar is a wrapper for [prometheus.ExemplarAdder.AddWithExemplar],
38
- // which falls back to [prometheus.Counter.Add] if no labels are provided.
39
- func addWithExemplar (obs prometheus.Counter , val float64 , labels map [string ]string ) {
40
- if labels == nil {
41
- obs .Add (val )
42
- return
43
- }
44
- obs .(prometheus.ExemplarAdder ).AddWithExemplar (val , labels )
45
- }
46
-
47
31
// InstrumentHandlerInFlight is a middleware that wraps the provided
48
32
// http.Handler. It sets the provided prometheus.Gauge to the number of
49
33
// requests currently handled by the wrapped http.Handler.
@@ -96,7 +80,7 @@ func InstrumentHandlerDuration(obs prometheus.ObserverVec, next http.Handler, op
96
80
for label , resolve := range hOpts .extraLabelsFromCtx {
97
81
l [label ] = resolve (r .Context ())
98
82
}
99
- observeWithExemplar ( obs .With (l ), time .Since (now ).Seconds (), hOpts .getExemplarFn (r .Context ()))
83
+ obs .With (l ).(prometheus. ExemplarObserver ). ObserveWithExemplar ( time .Since (now ).Seconds (), hOpts .getExemplarFn (r .Context ()))
100
84
}
101
85
}
102
86
@@ -107,7 +91,7 @@ func InstrumentHandlerDuration(obs prometheus.ObserverVec, next http.Handler, op
107
91
for label , resolve := range hOpts .extraLabelsFromCtx {
108
92
l [label ] = resolve (r .Context ())
109
93
}
110
- observeWithExemplar ( obs .With (l ), time .Since (now ).Seconds (), hOpts .getExemplarFn (r .Context ()))
94
+ obs .With (l ).(prometheus. ExemplarObserver ). ObserveWithExemplar ( time .Since (now ).Seconds (), hOpts .getExemplarFn (r .Context ()))
111
95
}
112
96
}
113
97
@@ -146,7 +130,7 @@ func InstrumentHandlerCounter(counter *prometheus.CounterVec, next http.Handler,
146
130
for label , resolve := range hOpts .extraLabelsFromCtx {
147
131
l [label ] = resolve (r .Context ())
148
132
}
149
- addWithExemplar ( counter .With (l ), 1 , hOpts .getExemplarFn (r .Context ()))
133
+ counter .With (l ).(prometheus. ExemplarAdder ). AddWithExemplar ( 1 , hOpts .getExemplarFn (r .Context ()))
150
134
}
151
135
}
152
136
@@ -157,7 +141,7 @@ func InstrumentHandlerCounter(counter *prometheus.CounterVec, next http.Handler,
157
141
for label , resolve := range hOpts .extraLabelsFromCtx {
158
142
l [label ] = resolve (r .Context ())
159
143
}
160
- addWithExemplar ( counter .With (l ), 1 , hOpts .getExemplarFn (r .Context ()))
144
+ counter .With (l ).(prometheus. ExemplarAdder ). AddWithExemplar ( 1 , hOpts .getExemplarFn (r .Context ()))
161
145
}
162
146
}
163
147
@@ -199,7 +183,7 @@ func InstrumentHandlerTimeToWriteHeader(obs prometheus.ObserverVec, next http.Ha
199
183
for label , resolve := range hOpts .extraLabelsFromCtx {
200
184
l [label ] = resolve (r .Context ())
201
185
}
202
- observeWithExemplar ( obs .With (l ), time .Since (now ).Seconds (), hOpts .getExemplarFn (r .Context ()))
186
+ obs .With (l ).(prometheus. ExemplarObserver ). ObserveWithExemplar ( time .Since (now ).Seconds (), hOpts .getExemplarFn (r .Context ()))
203
187
})
204
188
next .ServeHTTP (d , r )
205
189
}
@@ -243,7 +227,7 @@ func InstrumentHandlerRequestSize(obs prometheus.ObserverVec, next http.Handler,
243
227
for label , resolve := range hOpts .extraLabelsFromCtx {
244
228
l [label ] = resolve (r .Context ())
245
229
}
246
- observeWithExemplar ( obs .With (l ), float64 (size ), hOpts .getExemplarFn (r .Context ()))
230
+ obs .With (l ).(prometheus. ExemplarObserver ). ObserveWithExemplar ( float64 (size ), hOpts .getExemplarFn (r .Context ()))
247
231
}
248
232
}
249
233
@@ -255,7 +239,7 @@ func InstrumentHandlerRequestSize(obs prometheus.ObserverVec, next http.Handler,
255
239
for label , resolve := range hOpts .extraLabelsFromCtx {
256
240
l [label ] = resolve (r .Context ())
257
241
}
258
- observeWithExemplar ( obs .With (l ), float64 (size ), hOpts .getExemplarFn (r .Context ()))
242
+ obs .With (l ).(prometheus. ExemplarObserver ). ObserveWithExemplar ( float64 (size ), hOpts .getExemplarFn (r .Context ()))
259
243
}
260
244
}
261
245
@@ -295,7 +279,7 @@ func InstrumentHandlerResponseSize(obs prometheus.ObserverVec, next http.Handler
295
279
for label , resolve := range hOpts .extraLabelsFromCtx {
296
280
l [label ] = resolve (r .Context ())
297
281
}
298
- observeWithExemplar ( obs .With (l ), float64 (d .Written ()), hOpts .getExemplarFn (r .Context ()))
282
+ obs .With (l ).(prometheus. ExemplarObserver ). ObserveWithExemplar ( float64 (d .Written ()), hOpts .getExemplarFn (r .Context ()))
299
283
})
300
284
}
301
285
0 commit comments