pomerium/internal/telemetry/metrics/otel.go
Denis Mishin d9412f957a
metrics: don't add units and scope tags to prometheus metrics (#5749)
## Summary

With metrics now going via OTEL -> Prometheus exporter, there were
couple issues:

- some newer metrics had non-standard units that ended up in metric
names like `pomerium_storage_global_cache_hits__hit__total`
- we had three additional tags (`otel_scope_name`,
`otel_scope_schema_url`, `otel_scope_version`) added to each metric,
which do not really carry much meaningful information for us and expand
metric cardinality.

This PR reverts those two changes and updates the prometheus exporter.

## Related issues

Related: https://github.com/open-telemetry/opentelemetry-go/issues/7039

## User Explanation

<!-- How would you explain this change to the user? If this
change doesn't create any user-facing changes, you can leave
this blank. If filled out, add the `docs` label -->

## Checklist

- [x] reference any related issues
- [ ] updated unit tests
- [x] add appropriate label (`enhancement`, `bug`, `breaking`,
`dependencies`, `ci`)
- [x] ready for review
2025-07-24 14:34:11 -04:00

46 lines
1,015 B
Go

package metrics
import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/prometheus"
"go.opentelemetry.io/otel/metric"
sdk_metric "go.opentelemetry.io/otel/sdk/metric"
)
// Meter is the global meter for Pomerium.
var Meter metric.Meter
func init() {
e, err := prometheus.New(
prometheus.WithNamespace("pomerium"),
prometheus.WithoutUnits(),
prometheus.WithoutScopeInfo(),
)
if err != nil {
panic(err)
}
otel.SetMeterProvider(sdk_metric.NewMeterProvider(
sdk_metric.WithReader(e),
))
Meter = otel.Meter("")
}
// Int64Counter returns an int64 counter.
func Int64Counter(name string, options ...metric.Int64CounterOption) metric.Int64Counter {
c, err := Meter.Int64Counter(name, options...)
if err != nil {
panic(err)
}
return c
}
// Int64Histogram returns an int64 histogram.
func Int64Histogram(name string, options ...metric.Int64HistogramOption) metric.Int64Histogram {
c, err := Meter.Int64Histogram(name, options...)
if err != nil {
panic(err)
}
return c
}