Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Fixed

- Use `context.Background()` as default context instead of nil in `go.opentelemetry.io/contrib/bridges/otellogr`. (#6527)
- Convert Prometheus histogram buckets to non-cumulative otel histogram buckets in `go.opentelemetry.io/contrib/bridges/prometheus`. (#6685)
- Don't start spans that never end for filtered out gRPC stats handler in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#6695)

<!-- Released section -->
Expand Down
5 changes: 3 additions & 2 deletions bridges/prometheus/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,22 +296,23 @@ func convertBuckets(buckets []*dto.Bucket, sampleCount uint64) ([]float64, []uin
bucketCounts = make([]uint64, len(buckets)+1)
}
exemplars := make([]metricdata.Exemplar[float64], 0)
var previousCount uint64
for i, bucket := range buckets {
// The last bound may be the +Inf bucket, which is implied in OTel, but
// is explicit in Prometheus. Skip the last boundary if it is the +Inf
// bound.
if bound := bucket.GetUpperBound(); !math.IsInf(bound, +1) {
bounds[i] = bound
}
bucketCounts[i] = bucket.GetCumulativeCount()
previousCount, bucketCounts[i] = bucket.GetCumulativeCount(), bucket.GetCumulativeCount()-previousCount
if ex := bucket.GetExemplar(); ex != nil {
exemplars = append(exemplars, convertExemplar(ex))
}
}
if !hasInf {
// The Inf bucket was missing, so set the last bucket counts to the
// overall count
bucketCounts[len(bucketCounts)-1] = sampleCount
bucketCounts[len(bucketCounts)-1] = sampleCount - previousCount
}
return bounds, bucketCounts, exemplars
}
Expand Down
38 changes: 38 additions & 0 deletions bridges/prometheus/producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,44 @@ func TestProduce(t *testing.T) {
},
}},
},
{
name: "histogram cumulative values to non-cumulative",
testFn: func(reg *prometheus.Registry) {
metric := prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "test_histogram_metric",
Help: "A histogram metric for testing",
ConstLabels: prometheus.Labels(map[string]string{
"foo": "bar",
}),
})
reg.MustRegister(metric)
metric.Observe(0.01)
},
expected: []metricdata.ScopeMetrics{{
Scope: instrumentation.Scope{
Name: scopeName,
},
Metrics: []metricdata.Metrics{
{
Name: "test_histogram_metric",
Description: "A histogram metric for testing",
Data: metricdata.Histogram[float64]{
Temporality: metricdata.CumulativeTemporality,
Comment thread
MrAlias marked this conversation as resolved.
DataPoints: []metricdata.HistogramDataPoint[float64]{
{
Count: 1,
Sum: 0.01,
Bounds: []float64{0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10},
BucketCounts: []uint64{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Attributes: attribute.NewSet(attribute.String("foo", "bar")),
Exemplars: []metricdata.Exemplar[float64]{},
},
},
},
},
},
}},
},
{
name: "histogram with exemplar",
testFn: func(reg *prometheus.Registry) {
Expand Down