55 "log"
66 "net/http"
77 "os"
8+ "strings"
89
910 "github.com/prometheus/client_golang/prometheus"
1011 "github.com/prometheus/client_golang/prometheus/promhttp"
3334 Name : "http_request_duration_seconds" ,
3435 Help : "Duration of all HTTP requests" ,
3536 }, []string {"code" , "handler" , "method" })
37+
38+ httpRequestsTotalOtel = prometheus .NewCounterVec (prometheus.CounterOpts {
39+ Name : "http.server.requests" ,
40+ Help : "Count of HTTP requests per HTTP method (following the OpenTelemetry semantic conventions)" ,
41+ }, []string {"http.request.method" })
3642)
3743
3844func main () {
@@ -47,14 +53,17 @@ func main() {
4753 r := prometheus .NewRegistry ()
4854 r .MustRegister (httpRequestsTotal )
4955 r .MustRegister (httpRequestDuration )
56+ r .MustRegister (httpRequestsTotalOtel )
5057 r .MustRegister (version )
5158
5259 // Initialize the most likely labels.
5360 httpRequestDuration .WithLabelValues ("200" , foundHandlerName , "get" )
61+ httpRequestsTotalOtel .WithLabelValues ("get" )
5462 httpRequestsTotal .WithLabelValues ("200" , "get" )
5563 httpRequestsTotal .WithLabelValues ("404" , "get" )
5664
5765 foundHandler := http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
66+ httpRequestsTotalOtel .WithLabelValues (strings .ToLower (r .Method )).Inc ()
5867 w .WriteHeader (http .StatusOK )
5968 w .Write ([]byte ("Hello from example application." ))
6069 })
0 commit comments