-
Notifications
You must be signed in to change notification settings - Fork 899
/
metrics.go
43 lines (37 loc) · 891 Bytes
/
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
package header
import (
"context"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric/unit"
)
var meter = global.MeterProvider().Meter("header")
// MonitorHead enables Otel metrics to monitor head.
func MonitorHead(store Store) {
headC, _ := meter.AsyncInt64().Counter(
"head",
instrument.WithUnit(unit.Dimensionless),
instrument.WithDescription("Subjective head of the node"),
)
err := meter.RegisterCallback(
[]instrument.Asynchronous{
headC,
},
func(ctx context.Context) {
head, err := store.Head(ctx)
if err != nil {
headC.Observe(ctx, 0, attribute.String("err", err.Error()))
return
}
headC.Observe(
ctx,
head.Height,
attribute.Int("square_size", len(head.DAH.RowsRoots)),
)
},
)
if err != nil {
panic(err)
}
}