[chore] Bump all otel deps (#3241)

This commit is contained in:
tobi 2024-08-26 18:05:54 +02:00 committed by GitHub
commit 28d57d1f13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
193 changed files with 13714 additions and 2346 deletions

View file

@ -0,0 +1,3 @@
# Prometheus Exporter
[![PkgGoDev](https://pkg.go.dev/badge/go.opentelemetry.io/otel/exporters/prometheus)](https://pkg.go.dev/go.opentelemetry.io/otel/exporters/prometheus)

View file

@ -1,16 +1,5 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: Apache-2.0
package prometheus // import "go.opentelemetry.io/otel/exporters/prometheus"

View file

@ -1,16 +1,5 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: Apache-2.0
// Package prometheus provides a Prometheus Exporter that converts
// OTLP metrics into the Prometheus exposition format and implements

View file

@ -1,24 +1,14 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: Apache-2.0
package prometheus // import "go.opentelemetry.io/otel/exporters/prometheus"
import (
"context"
"encoding/hex"
"errors"
"fmt"
"sort"
"slices"
"strings"
"sync"
"unicode"
@ -43,6 +33,9 @@ const (
scopeInfoMetricName = "otel_scope_info"
scopeInfoDescription = "Instrumentation Scope metadata"
traceIDExemplarKey = "trace_id"
spanIDExemplarKey = "span_id"
)
var (
@ -199,7 +192,7 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) {
if !c.disableScopeInfo {
scopeInfo, err := c.scopeInfo(scopeMetrics.Scope)
if err == errScopeInvalid {
if errors.Is(err, errScopeInvalid) {
// Do not report the same error multiple times.
continue
}
@ -249,7 +242,6 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) {
}
func addHistogramMetric[N int64 | float64](ch chan<- prometheus.Metric, histogram metricdata.Histogram[N], m metricdata.Metrics, ks, vs [2]string, name string, resourceKV keyVals) {
// TODO(https://github.com/open-telemetry/opentelemetry-go/issues/3163): support exemplars
for _, dp := range histogram.DataPoints {
keys, values := getAttrs(dp.Attributes, ks, vs, resourceKV)
@ -266,6 +258,7 @@ func addHistogramMetric[N int64 | float64](ch chan<- prometheus.Metric, histogra
otel.Handle(err)
continue
}
m = addExemplars(m, dp.Exemplars)
ch <- m
}
}
@ -285,6 +278,7 @@ func addSumMetric[N int64 | float64](ch chan<- prometheus.Metric, sum metricdata
otel.Handle(err)
continue
}
m = addExemplars(m, dp.Exemplars)
ch <- m
}
}
@ -324,9 +318,7 @@ func getAttrs(attrs attribute.Set, ks, vs [2]string, resourceKV keyVals) ([]stri
values := make([]string, 0, attrs.Len())
for key, vals := range keysMap {
keys = append(keys, key)
sort.Slice(vals, func(i, j int) bool {
return i < j
})
slices.Sort(vals)
values = append(values, strings.Join(vals, ";"))
}
@ -562,3 +554,37 @@ func (c *collector) validateMetrics(name, description string, metricType *dto.Me
return false, ""
}
func addExemplars[N int64 | float64](m prometheus.Metric, exemplars []metricdata.Exemplar[N]) prometheus.Metric {
if len(exemplars) == 0 {
return m
}
promExemplars := make([]prometheus.Exemplar, len(exemplars))
for i, exemplar := range exemplars {
labels := attributesToLabels(exemplar.FilteredAttributes)
// Overwrite any existing trace ID or span ID attributes
labels[traceIDExemplarKey] = hex.EncodeToString(exemplar.TraceID[:])
labels[spanIDExemplarKey] = hex.EncodeToString(exemplar.SpanID[:])
promExemplars[i] = prometheus.Exemplar{
Value: float64(exemplar.Value),
Timestamp: exemplar.Time,
Labels: labels,
}
}
metricWithExemplar, err := prometheus.NewMetricWithExemplars(m, promExemplars...)
if err != nil {
// If there are errors creating the metric with exemplars, just warn
// and return the metric without exemplars.
otel.Handle(err)
return m
}
return metricWithExemplar
}
func attributesToLabels(attrs []attribute.KeyValue) prometheus.Labels {
labels := make(map[string]string)
for _, attr := range attrs {
labels[string(attr.Key)] = attr.Value.Emit()
}
return labels
}