Skip to content

How can I setup /metrics handler to expose the default metrics collected by ogen server? #1239

Answered by tdakkota
zwpaper asked this question in Q&A
Discussion options

You must be logged in to vote

You can create a Prometheus MeterProvider by yourself:

exporter, err := prometheus.New()
if err != nil {
	return err
}
provider := metric.NewMeterProvider(metric.WithReader(exporter))

srv, err := <api_package>.NewServer(<api_package>.WithMeterProvider(provider))
if err != nil {
	return err
}

http.Handle("/metrics", promhttp.Handler())
http.Handle("/api", http.StripPrefix("/api", srv))
http.ListenAndServe(":8080", nil)

There is OpenTelemery SDK example.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@zwpaper
Comment options

Answer selected by zwpaper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants