You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The resulting unit SHOULD be added to the metric as OpenMetrics UNIT metadata and as a suffix to the metric name unless the metric name already contains the unit, or the unit MUST be omitted. The unit suffix comes before any type-specific suffixes.
But this doesn't happen.
counter, err := meter.Float64Counter("foo", api.WithDescription("a simple counter"), api.WithUnit("s")) results in
# HELP foo_total a simple counter
# TYPE foo_total counter
foo_total{A="B",C="D",otel_scope_name="github.com/open-telemetry/opentelemetry-go/example/prometheus",otel_scope_version=""} 5
Environment
OS: MacOS
Architecture: darwin/arm64
Go Version: 1.20.6
opentelemetry-go version: 1.16.0
Steps To Reproduce
The exporter embeds a default OpenTelemetry Reader and
// implements prometheus.Collector, allowing it to be used as
// both a Reader and Collector.
exporter, err := prometheus.New()
if err != nil {
log.Fatal(err)
}
provider := metric.NewMeterProvider(metric.WithReader(exporter))
meter := provider.Meter("github.com/open-telemetry/opentelemetry-go/example/prometheus")
// Start the prometheus HTTP server and pass the exporter Collector to it
go serveMetrics()
opt := api.WithAttributes(
attribute.Key("A").String("B"),
attribute.Key("C").String("D"),
)
// This is the equivalent of prometheus.NewCounterVec
counter, err := meter.Float64Counter("foo", api.WithDescription("a simple counter"), api.WithUnit("s"))
if err != nil {
log.Fatal(err)
}
counter.Add(ctx, 5, opt)
ctx, _ = signal.NotifyContext(ctx, os.Interrupt)
<-ctx.Done()
}
func serveMetrics() {
log.Printf("serving metrics at localhost:2223/metrics")
http.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(":2223", nil)
if err != nil {
fmt.Printf("error serving http: %v", err)
return
}
}
The text was updated successfully, but these errors were encountered:
We do support units, but decided originally to only support the units defined by the Go SDK. I think we've since removed our constants for units, so it makes sense to expand what the prom exporter supports.
Description
The Prometheus compatibility spec specifies:
But this doesn't happen.
counter, err := meter.Float64Counter("foo", api.WithDescription("a simple counter"), api.WithUnit("s"))
results inEnvironment
Steps To Reproduce
The text was updated successfully, but these errors were encountered: