-
Notifications
You must be signed in to change notification settings - Fork 0
/
otel_helpers.go
61 lines (55 loc) · 1.46 KB
/
otel_helpers.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
package aqi2otel
import (
"context"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric/instrument/syncfloat64"
"go.opentelemetry.io/otel/metric/instrument/syncint64"
)
func newInt64Counter(meter metric.Meter, name string) syncint64.Counter {
counter, err := meter.SyncInt64().Counter(name)
if err != nil {
panic(err)
}
return counter
}
func newFloat64Counter(meter metric.Meter, name string) syncfloat64.Counter {
counter, err := meter.SyncFloat64().Counter(name)
if err != nil {
panic(err)
}
return counter
}
func setNewInt64Gauge(ctx context.Context, meter metric.Meter, sensorName, name string, val int64) {
gauge, err := meter.AsyncInt64().Gauge(name)
if err != nil {
panic(err)
}
err = meter.RegisterCallback(
[]instrument.Asynchronous{gauge},
func(ctx context.Context) {
//log.Println("Got callback for " + name)
gauge.Observe(ctx, val, attribute.String("name", sensorName))
},
)
if err != nil {
panic(err)
}
}
func setNewFloat64Gauge(ctx context.Context, meter metric.Meter, sensorName, name string, val float64) {
gauge, err := meter.AsyncFloat64().Gauge(name)
if err != nil {
panic(err)
}
err = meter.RegisterCallback(
[]instrument.Asynchronous{gauge},
func(ctx context.Context) {
//log.Println("Got callback for " + name)
gauge.Observe(ctx, val, attribute.String("name", sensorName))
},
)
if err != nil {
panic(err)
}
}