Upgrade opentelemetry dependencies
This commit is contained in:
parent
c7cd0df3b3
commit
d141e4a1ed
4 changed files with 69 additions and 79 deletions
|
@ -12,14 +12,12 @@ import (
|
|||
"github.com/rs/zerolog/log"
|
||||
"github.com/traefik/traefik/v3/pkg/types"
|
||||
"github.com/traefik/traefik/v3/pkg/version"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/global"
|
||||
"go.opentelemetry.io/otel/metric/instrument"
|
||||
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregation"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
|
||||
"google.golang.org/grpc/credentials"
|
||||
|
@ -41,12 +39,11 @@ func RegisterOpenTelemetry(ctx context.Context, config *types.OpenTelemetry) Reg
|
|||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if openTelemetryGaugeCollector == nil {
|
||||
openTelemetryGaugeCollector = newOpenTelemetryGaugeCollector()
|
||||
}
|
||||
|
||||
meter := global.Meter("github.com/traefik/traefik",
|
||||
meter := otel.Meter("github.com/traefik/traefik",
|
||||
metric.WithInstrumentationVersion(version.Version))
|
||||
|
||||
reg := &standardRegistry{
|
||||
|
@ -160,13 +157,13 @@ func newOpenTelemetryMeterProvider(ctx context.Context, config *types.OpenTeleme
|
|||
// View to customize histogram buckets and rename a single histogram instrument.
|
||||
sdkmetric.WithView(sdkmetric.NewView(
|
||||
sdkmetric.Instrument{Name: "traefik_*_request_duration_seconds"},
|
||||
sdkmetric.Stream{Aggregation: aggregation.ExplicitBucketHistogram{
|
||||
sdkmetric.Stream{Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
|
||||
Boundaries: config.ExplicitBoundaries,
|
||||
}},
|
||||
)),
|
||||
)
|
||||
|
||||
global.SetMeterProvider(meterProvider)
|
||||
otel.SetMeterProvider(meterProvider)
|
||||
|
||||
return meterProvider, nil
|
||||
}
|
||||
|
@ -233,8 +230,8 @@ func newGRPCExporter(ctx context.Context, config *types.OpenTelemetry) (sdkmetri
|
|||
|
||||
func newOTLPCounterFrom(meter metric.Meter, name, desc string) *otelCounter {
|
||||
c, _ := meter.Float64Counter(name,
|
||||
instrument.WithDescription(desc),
|
||||
instrument.WithUnit("1"),
|
||||
metric.WithDescription(desc),
|
||||
metric.WithUnit("1"),
|
||||
)
|
||||
|
||||
return &otelCounter{
|
||||
|
@ -244,7 +241,7 @@ func newOTLPCounterFrom(meter metric.Meter, name, desc string) *otelCounter {
|
|||
|
||||
type otelCounter struct {
|
||||
labelNamesValues otelLabelNamesValues
|
||||
ip instrument.Float64Counter
|
||||
ip metric.Float64Counter
|
||||
}
|
||||
|
||||
func (c *otelCounter) With(labelValues ...string) metrics.Counter {
|
||||
|
@ -255,7 +252,7 @@ func (c *otelCounter) With(labelValues ...string) metrics.Counter {
|
|||
}
|
||||
|
||||
func (c *otelCounter) Add(delta float64) {
|
||||
c.ip.Add(context.Background(), delta, c.labelNamesValues.ToLabels()...)
|
||||
c.ip.Add(context.Background(), delta, metric.WithAttributes(c.labelNamesValues.ToLabels()...))
|
||||
}
|
||||
|
||||
type gaugeValue struct {
|
||||
|
@ -323,8 +320,8 @@ func newOTLPGaugeFrom(meter metric.Meter, name, desc string, unit string) *otelG
|
|||
openTelemetryGaugeCollector.values[name] = make(map[string]gaugeValue)
|
||||
|
||||
c, _ := meter.Float64ObservableGauge(name,
|
||||
instrument.WithDescription(desc),
|
||||
instrument.WithUnit(unit),
|
||||
metric.WithDescription(desc),
|
||||
metric.WithUnit(unit),
|
||||
)
|
||||
|
||||
_, err := meter.RegisterCallback(func(ctx context.Context, observer metric.Observer) error {
|
||||
|
@ -337,7 +334,7 @@ func newOTLPGaugeFrom(meter metric.Meter, name, desc string, unit string) *otelG
|
|||
}
|
||||
|
||||
for _, value := range values {
|
||||
observer.ObserveFloat64(c, value.value, value.attributes.ToLabels()...)
|
||||
observer.ObserveFloat64(c, value.value, metric.WithAttributes(value.attributes.ToLabels()...))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -354,7 +351,7 @@ func newOTLPGaugeFrom(meter metric.Meter, name, desc string, unit string) *otelG
|
|||
|
||||
type otelGauge struct {
|
||||
labelNamesValues otelLabelNamesValues
|
||||
ip instrument.Float64ObservableGauge
|
||||
ip metric.Float64ObservableGauge
|
||||
name string
|
||||
}
|
||||
|
||||
|
@ -376,8 +373,8 @@ func (g *otelGauge) Set(value float64) {
|
|||
|
||||
func newOTLPHistogramFrom(meter metric.Meter, name, desc string, unit string) *otelHistogram {
|
||||
c, _ := meter.Float64Histogram(name,
|
||||
instrument.WithDescription(desc),
|
||||
instrument.WithUnit(unit),
|
||||
metric.WithDescription(desc),
|
||||
metric.WithUnit(unit),
|
||||
)
|
||||
|
||||
return &otelHistogram{
|
||||
|
@ -387,7 +384,7 @@ func newOTLPHistogramFrom(meter metric.Meter, name, desc string, unit string) *o
|
|||
|
||||
type otelHistogram struct {
|
||||
labelNamesValues otelLabelNamesValues
|
||||
ip instrument.Float64Histogram
|
||||
ip metric.Float64Histogram
|
||||
}
|
||||
|
||||
func (h *otelHistogram) With(labelValues ...string) metrics.Histogram {
|
||||
|
@ -398,7 +395,7 @@ func (h *otelHistogram) With(labelValues ...string) metrics.Histogram {
|
|||
}
|
||||
|
||||
func (h *otelHistogram) Observe(incr float64) {
|
||||
h.ip.Record(context.Background(), incr, h.labelNamesValues.ToLabels()...)
|
||||
h.ip.Record(context.Background(), incr, metric.WithAttributes(h.labelNamesValues.ToLabels()...))
|
||||
}
|
||||
|
||||
// otelLabelNamesValues is the equivalent of prometheus' labelNamesValues
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue