/
number_datapoint.go
46 lines (38 loc) · 1.02 KB
/
number_datapoint.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
package data
import (
v1metrics "go.opentelemetry.io/proto/otlp/metrics/v1"
)
type NumberDataPoint struct {
raw *v1metrics.NumberDataPoint
}
func WithNumberDataPointDelimtedTags[Tags ~[]string](tags Tags) func(NumberDataPoint) {
return func(ndp NumberDataPoint) {
ndp.raw.Attributes = NewMap(WithStatsdDelimitedTags(tags)).unwrap()
}
}
func WithNumberDatapointIntValue(value int64) func(NumberDataPoint) {
return func(ndp NumberDataPoint) {
ndp.raw.Value = &v1metrics.NumberDataPoint_AsInt{
AsInt: value,
}
}
}
func WithNumberDataPointDoubleValue(value float64) func(NumberDataPoint) {
return func(ndp NumberDataPoint) {
ndp.raw.Value = &v1metrics.NumberDataPoint_AsDouble{
AsDouble: value,
}
}
}
// NewNumberDataPoint applies options in order so the last value set wins
func NewNumberDataPoint(timestamp uint64, opts ...func(NumberDataPoint)) NumberDataPoint {
dp := NumberDataPoint{
raw: &v1metrics.NumberDataPoint{
TimeUnixNano: timestamp,
},
}
for _, opt := range opts {
opt(dp)
}
return dp
}