diff --git a/examples/hotrod/pkg/tracing/http.go b/examples/hotrod/pkg/tracing/http.go index 1ceca45197a..b82cccc556f 100644 --- a/examples/hotrod/pkg/tracing/http.go +++ b/examples/hotrod/pkg/tracing/http.go @@ -30,10 +30,10 @@ type HTTPClient struct { Client *http.Client } -func NewHTTPClient(tp trace.TracerProvider) HTTPClient { - return HTTPClient{ +func NewHTTPClient(tp trace.TracerProvider) *HTTPClient { + return &HTTPClient{ TracerProvider: tp, - Client: &http.Client{Transport: &otelhttp.Transport{}}, + Client: &http.Client{Transport: otelhttp.NewTransport(http.DefaultTransport, otelhttp.WithTracerProvider(tp))}, } } diff --git a/examples/hotrod/pkg/tracing/mux.go b/examples/hotrod/pkg/tracing/mux.go index 5e41d4c3650..01d841e969d 100644 --- a/examples/hotrod/pkg/tracing/mux.go +++ b/examples/hotrod/pkg/tracing/mux.go @@ -26,25 +26,29 @@ import ( ) // NewServeMux creates a new TracedServeMux. -func NewServeMux(tracer trace.TracerProvider, logger log.Factory) *TracedServeMux { +func NewServeMux(copyBaggage bool, tracer trace.TracerProvider, logger log.Factory) *TracedServeMux { return &TracedServeMux{ - mux: http.NewServeMux(), - tracer: tracer, - logger: logger, + mux: http.NewServeMux(), + copyBaggage: copyBaggage, + tracer: tracer, + logger: logger, } } // TracedServeMux is a wrapper around http.ServeMux that instruments handlers for tracing. type TracedServeMux struct { - mux *http.ServeMux - tracer trace.TracerProvider - logger log.Factory + mux *http.ServeMux + copyBaggage bool + tracer trace.TracerProvider + logger log.Factory } // Handle implements http.ServeMux#Handle, which is used to register new handler. func (tm *TracedServeMux) Handle(pattern string, handler http.Handler) { tm.logger.Bg().Debug("registering traced handler", zap.String("endpoint", pattern)) + otelhttp.WithRouteTag(pattern, handler) + middleware := otelhttp.NewHandler(handler, pattern, otelhttp.WithTracerProvider(tm.tracer)) tm.mux.Handle(pattern, middleware) diff --git a/examples/hotrod/services/customer/client.go b/examples/hotrod/services/customer/client.go index 291fc208c6b..8514d0f140f 100644 --- a/examples/hotrod/services/customer/client.go +++ b/examples/hotrod/services/customer/client.go @@ -29,7 +29,7 @@ import ( // Client is a remote client that implements customer.Interface type Client struct { logger log.Factory - client tracing.HTTPClient + client *tracing.HTTPClient hostPort string } diff --git a/examples/hotrod/services/customer/server.go b/examples/hotrod/services/customer/server.go index 06d15ba940d..475d21c4ad5 100644 --- a/examples/hotrod/services/customer/server.go +++ b/examples/hotrod/services/customer/server.go @@ -19,7 +19,6 @@ import ( "encoding/json" "net/http" - "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" "go.opentelemetry.io/otel/trace" "go.uber.org/zap" @@ -58,8 +57,8 @@ func (s *Server) Run() error { } func (s *Server) createServeMux() http.Handler { - mux := tracing.NewServeMux(s.tracer, s.logger) - mux.Handle("/customer", otelhttp.WithRouteTag("/customer", http.HandlerFunc(s.customer))) + mux := tracing.NewServeMux(false, s.tracer, s.logger) + mux.Handle("/customer", http.HandlerFunc(s.customer)) return mux } diff --git a/examples/hotrod/services/frontend/best_eta.go b/examples/hotrod/services/frontend/best_eta.go index fdd6c9442a2..27924b6810c 100644 --- a/examples/hotrod/services/frontend/best_eta.go +++ b/examples/hotrod/services/frontend/best_eta.go @@ -22,7 +22,6 @@ import ( "sync" "time" - "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" "go.uber.org/zap" @@ -77,9 +76,6 @@ func (eta *bestETA) Get(ctx context.Context, customerID string) (*Response, erro } eta.logger.For(ctx).Info("Found customer", zap.Any("customer", customer)) - span := trace.SpanFromContext(ctx) - span.AddEvent("customer", trace.WithAttributes(attribute.Key(customer.Name).String(customer.Location))) - drivers, err := eta.driver.FindNearest(ctx, customer.Location) if err != nil { return nil, err diff --git a/examples/hotrod/services/frontend/server.go b/examples/hotrod/services/frontend/server.go index a56be66a4d5..45527569f85 100644 --- a/examples/hotrod/services/frontend/server.go +++ b/examples/hotrod/services/frontend/server.go @@ -76,7 +76,7 @@ func (s *Server) Run() error { } func (s *Server) createServeMux() http.Handler { - mux := tracing.NewServeMux(s.tracer, s.logger) + mux := tracing.NewServeMux(true, s.tracer, s.logger) p := path.Join("/", s.basepath) mux.Handle(p, http.StripPrefix(p, http.FileServer(s.assetFS))) mux.Handle(path.Join(p, "/dispatch"), http.HandlerFunc(s.dispatch)) diff --git a/examples/hotrod/services/route/client.go b/examples/hotrod/services/route/client.go index 4832f27a136..9448c21cfe6 100644 --- a/examples/hotrod/services/route/client.go +++ b/examples/hotrod/services/route/client.go @@ -29,7 +29,7 @@ import ( // Client is a remote client that implements route.Interface type Client struct { logger log.Factory - client tracing.HTTPClient + client *tracing.HTTPClient hostPort string } diff --git a/examples/hotrod/services/route/server.go b/examples/hotrod/services/route/server.go index 9cba5932c0a..9d2643f9301 100644 --- a/examples/hotrod/services/route/server.go +++ b/examples/hotrod/services/route/server.go @@ -59,7 +59,7 @@ func (s *Server) Run() error { } func (s *Server) createServeMux() http.Handler { - mux := tracing.NewServeMux(s.tracer, s.logger) + mux := tracing.NewServeMux(false, s.tracer, s.logger) mux.Handle("/route", http.HandlerFunc(s.route)) mux.Handle("/debug/vars", expvar.Handler()) // expvar mux.Handle("/metrics", promhttp.Handler()) // Prometheus