-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
otelmetric_metric_callback.go
56 lines (50 loc) · 1.8 KB
/
otelmetric_metric_callback.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
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package otelmetric
import (
"go.opentelemetry.io/otel/metric"
"github.com/gogf/gf/v2/os/gmetric"
)
// localMetricObserver implements interface gmetric.CallbackObserver.
type localMetricObserver struct {
gmetric.MeterOption
gmetric.MetricOption
metric.Float64Observer
}
func (l *localMeterPerformer) newMetricObserver(
metricOption gmetric.MetricOption,
float64Observer metric.Float64Observer,
) gmetric.MetricObserver {
return &localMetricObserver{
MeterOption: l.MeterOption,
MetricOption: metricOption,
Float64Observer: float64Observer,
}
}
// Observe observes the value for certain initialized Metric.
// It adds the value to total result if the observed Metrics is type of Counter.
// It sets the value as the result if the observed Metrics is type of Gauge.
func (l *localMetricObserver) Observe(value float64, option ...gmetric.Option) {
var (
constOption = genConstOptionForMetric(l.MeterOption, l.MetricOption)
dynamicOption = getDynamicOptionByMetricOption(option...)
globalAttributesOption = getGlobalAttributesOption(gmetric.GetGlobalAttributesOption{
Instrument: l.Instrument,
InstrumentVersion: l.InstrumentVersion,
})
observeOptions = make([]metric.ObserveOption, 0)
)
if globalAttributesOption != nil {
observeOptions = append(observeOptions, globalAttributesOption)
}
if constOption != nil {
observeOptions = append(observeOptions, constOption)
}
if dynamicOption != nil {
observeOptions = append(observeOptions, dynamicOption)
}
l.Float64Observer.Observe(value, observeOptions...)
}