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
package main
import (
"context""log""net/http""os""os/signal""github.com/prometheus/client_golang/prometheus""github.com/prometheus/client_golang/prometheus/promhttp"
otelprom "go.opentelemetry.io/otel/exporters/prometheus""go.opentelemetry.io/otel/metric/instrument""go.opentelemetry.io/otel/sdk/metric"
)
funcmain() {
ctx:=context.Background()
// The exporter embeds a default OpenTelemetry Reader and// implements prometheus.Collector, allowing it to be used as// both a Reader and Collector.exporter:=otelprom.New()
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 itregistry:=prometheus.NewRegistry()
err:=registry.Register(exporter.Collector)
iferr!=nil {
log.Fatal(err)
}
log.Printf("serving metrics at localhost:2222/metrics")
http.Handle("/metrics", promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
gohttp.ListenAndServe(":2222", nil)
histogram, err:=meter.SyncFloat64().Histogram(
"invalid.name.latency",
instrument.WithDescription("a histogram with an invalid name"),
)
iferr!=nil {
log.Fatal(err)
}
histogram.Record(ctx, 23)
ctx, _=signal.NotifyContext(ctx, os.Interrupt)
<-ctx.Done()
}
Run the above code
$ go run .
2022/09/16 13:09:46 serving metrics at localhost:2222/metrics
Description
Running the prometheus exporter with an instrument that has an invalid name causes the HTTP server to panic.
Environment
Steps To Reproduce
go.mod
:main.go
:curl localhost:2222/metrics
Output:
Expected behavior
No Panic
The text was updated successfully, but these errors were encountered: