-
Notifications
You must be signed in to change notification settings - Fork 42
/
queue_metric.go
47 lines (39 loc) · 775 Bytes
/
queue_metric.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
package gobrake
import (
"context"
)
type QueueMetric struct {
metric
Queue string
Errored bool
root Span
}
var _ Metric = (*QueueMetric)(nil)
func NewQueueMetric(c context.Context, name string) (context.Context, *QueueMetric) {
t := &QueueMetric{
Queue: name,
}
t.metric.init()
if c != nil {
c = withMetric(c, t)
}
c, t.root = t.Start(c, "queue.handler")
return c, t
}
func ContextQueueMetric(c context.Context) *QueueMetric {
if c == nil {
return nil
}
t, _ := c.Value(metricCtxKey).(*QueueMetric)
return t
}
func (t *QueueMetric) Start(c context.Context, name string) (context.Context, Span) {
if t == nil {
return c, noopSpan{}
}
return t.metric.Start(c, name)
}
func (t *QueueMetric) finish() {
t.root.Finish()
t.metric.finish()
}