From 01d8d86c7cb117375ad6cc85e5d82dda161fcf15 Mon Sep 17 00:00:00 2001 From: matst80 Date: Wed, 5 Nov 2025 18:46:17 +0100 Subject: [PATCH] manual handler --- cmd/cart/checkout_server.go | 2 +- cmd/cart/pool-server.go | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cmd/cart/checkout_server.go b/cmd/cart/checkout_server.go index a58f193..c1ad53c 100644 --- a/cmd/cart/checkout_server.go +++ b/cmd/cart/checkout_server.go @@ -29,7 +29,7 @@ func (a *App) HandleCheckoutRequests(amqpUrl string, mux *http.ServeMux) { orderHandler := NewAmqpOrderHandler(conn) orderHandler.DefineTopics() - mux.HandleFunc("/push", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("POST /push", func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { w.WriteHeader(http.StatusMethodNotAllowed) diff --git a/cmd/cart/pool-server.go b/cmd/cart/pool-server.go index 8e83635..a4e69cf 100644 --- a/cmd/cart/pool-server.go +++ b/cmd/cart/pool-server.go @@ -19,8 +19,10 @@ import ( "github.com/prometheus/client_golang/prometheus/promauto" "go.opentelemetry.io/contrib/bridges/otelslog" "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" + "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconv" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) var ( @@ -574,9 +576,16 @@ func (s *PoolServer) Serve(mux *http.ServeMux) { // }) handleFunc := func(pattern string, handlerFunc func(http.ResponseWriter, *http.Request)) { - // Configure the "http.route" for the HTTP instrumentation. - handler := otelhttp.WithRouteTag(pattern, http.HandlerFunc(handlerFunc)) - mux.Handle(pattern, handler) + attr := semconv.NewHTTPServer(nil).Route(pattern) + mux.HandleFunc(pattern, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + span := trace.SpanFromContext(r.Context()) + span.SetAttributes(attr) + + labeler, _ := otelhttp.LabelerFromContext(r.Context()) + labeler.Add(attr) + + handlerFunc(w, r) + })) } handleFunc("GET /cart", CookieCartIdHandler(s.ProxyHandler(s.GetCartHandler)))