代码拉取完成,页面将自动刷新
// 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 (
"context"
"go.opentelemetry.io/otel/metric"
"gitee.com/clannad_sk/webkit/v2/encoding/gjson"
"gitee.com/clannad_sk/webkit/v2/errors/gcode"
"gitee.com/clannad_sk/webkit/v2/errors/gerror"
"gitee.com/clannad_sk/webkit/v2/os/gmetric"
)
// localHistogramPerformer is an implementer for interface HistogramPerformer.
type localHistogramPerformer struct {
gmetric.MeterOption
gmetric.MetricOption
metric.Float64Histogram
constOption metric.MeasurementOption
}
// newHistogramPerformer creates and returns a HistogramPerformer that truly takes action to implement Histogram.
func (l *localMeterPerformer) newHistogramPerformer(
meter metric.Meter,
metricName string,
metricOption gmetric.MetricOption,
) (gmetric.HistogramPerformer, error) {
histogram, err := meter.Float64Histogram(
metricName,
metric.WithDescription(metricOption.Help),
metric.WithUnit(metricOption.Unit),
metric.WithExplicitBucketBoundaries(metricOption.Buckets...),
)
if err != nil {
return nil, gerror.WrapCodef(
gcode.CodeInternalError,
err,
`create Float64Histogram "%s" failed with option: %s`,
metricName, gjson.MustEncodeString(metricOption),
)
}
return &localHistogramPerformer{
MeterOption: l.MeterOption,
MetricOption: metricOption,
Float64Histogram: histogram,
constOption: genConstOptionForMetric(l.MeterOption, metricOption),
}, nil
}
// Record adds a single value to the histogram. The value is usually positive or zero.
func (l *localHistogramPerformer) Record(increment float64, option ...gmetric.Option) {
l.Float64Histogram.Record(
context.Background(),
increment,
l.generateRecordOptions(option...)...,
)
}
func (l *localHistogramPerformer) generateRecordOptions(option ...gmetric.Option) []metric.RecordOption {
var (
dynamicOption = getDynamicOptionByMetricOption(option...)
recordOptions = make([]metric.RecordOption, 0)
globalAttributesOption = getGlobalAttributesOption(gmetric.GetGlobalAttributesOption{
Instrument: l.MeterOption.Instrument,
InstrumentVersion: l.MeterOption.InstrumentVersion,
})
)
if globalAttributesOption != nil {
recordOptions = append(recordOptions, globalAttributesOption)
}
if l.constOption != nil {
recordOptions = append(recordOptions, l.constOption)
}
if dynamicOption != nil {
recordOptions = append(recordOptions, dynamicOption)
}
return recordOptions
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。