diff --git a/examples/hotrod/cmd/route.go b/examples/hotrod/cmd/route.go index 191bd96c556..04cf3687076 100644 --- a/examples/hotrod/cmd/route.go +++ b/examples/hotrod/cmd/route.go @@ -37,7 +37,7 @@ var routeCmd = &cobra.Command{ logger := log.NewFactory(zapLogger) server := route.NewServer( net.JoinHostPort("0.0.0.0", strconv.Itoa(routePort)), - tracing.Init("route", otelExporter, metricsFactory, logger), + tracing.InitOTEL("route", otelExporter, metricsFactory, logger), logger, ) return logError(zapLogger, server.Run()) diff --git a/examples/hotrod/pkg/tracing/mux.go b/examples/hotrod/pkg/tracing/mux.go index a9102f2ccb4..ac35e86c0ce 100644 --- a/examples/hotrod/pkg/tracing/mux.go +++ b/examples/hotrod/pkg/tracing/mux.go @@ -18,17 +18,16 @@ package tracing import ( "net/http" - "github.com/opentracing-contrib/go-stdlib/nethttp" - "github.com/opentracing/opentracing-go" - "go.opentelemetry.io/otel/baggage" + "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/trace" "go.uber.org/zap" "github.com/jaegertracing/jaeger/examples/hotrod/pkg/log" ) // NewServeMux creates a new TracedServeMux. -func NewServeMux(copyBaggage bool, tracer opentracing.Tracer, logger log.Factory) *TracedServeMux { +func NewServeMux(copyBaggage bool, tracer trace.TracerProvider, logger log.Factory) *TracedServeMux { return &TracedServeMux{ mux: http.NewServeMux(), copyBaggage: copyBaggage, @@ -41,7 +40,7 @@ func NewServeMux(copyBaggage bool, tracer opentracing.Tracer, logger log.Factory type TracedServeMux struct { mux *http.ServeMux copyBaggage bool - tracer opentracing.Tracer + tracer trace.TracerProvider logger log.Factory } @@ -49,28 +48,8 @@ type TracedServeMux struct { func (tm *TracedServeMux) Handle(pattern string, handler http.Handler) { tm.logger.Bg().Debug("registering traced handler", zap.String("endpoint", pattern)) - middleware := nethttp.Middleware( - tm.tracer, - handler, - nethttp.OperationNameFunc(func(r *http.Request) string { - return "HTTP " + r.Method + " " + pattern - }), - // Jaeger SDK was able to accept `jaeger-baggage` header even for requests without am active trace. - // OTEL Bridge does not support that, so we use Baggage propagator to manually extract the baggage - // into Context (in otelBaggageExtractor handler below), and once the Bridge creates a Span, - // we use this SpanObserver to copy OTEL baggage from Context into the Span. - nethttp.MWSpanObserver(func(span opentracing.Span, r *http.Request) { - if !tm.copyBaggage { - return - } - bag := baggage.FromContext(r.Context()) - for _, m := range bag.Members() { - if b := span.BaggageItem(m.Key()); b == "" { - span.SetBaggageItem(m.Key(), m.Value()) - } - } - }), - ) + middleware := otelhttp.NewHandler(tm.mux, pattern, + otelhttp.WithTracerProvider(tm.tracer)) tm.mux.Handle(pattern, otelBaggageExtractor(middleware)) } diff --git a/examples/hotrod/services/customer/server.go b/examples/hotrod/services/customer/server.go index b1bc69697cb..91383b4a6bf 100644 --- a/examples/hotrod/services/customer/server.go +++ b/examples/hotrod/services/customer/server.go @@ -32,7 +32,6 @@ import ( // Server implements Customer service type Server struct { hostPort string - mux http.ServeMux tracer trace.TracerProvider logger log.Factory database *database @@ -55,13 +54,13 @@ func NewServer(hostPort string, otelExporter string, metricsFactory metrics.Fact func (s *Server) Run() error { mux := s.createServeMux() s.logger.Bg().Info("Starting", zap.String("address", "http://"+s.hostPort)) - return http.ListenAndServe(s.hostPort, otelhttp.NewHandler(mux, "/customer", - otelhttp.WithTracerProvider(s.tracer))) + return http.ListenAndServe(s.hostPort, mux) } func (s *Server) createServeMux() http.Handler { - s.mux.Handle("/customer", otelhttp.WithRouteTag("/customer", http.HandlerFunc(s.customer))) - return &s.mux + mux := tracing.NewServeMux(false, s.tracer, s.logger) + mux.Handle("/customer", otelhttp.WithRouteTag("/customer", http.HandlerFunc(s.customer))) + return mux } func (s *Server) customer(w http.ResponseWriter, r *http.Request) { diff --git a/examples/hotrod/services/frontend/server.go b/examples/hotrod/services/frontend/server.go index 0a13f18e744..926ce5623c9 100644 --- a/examples/hotrod/services/frontend/server.go +++ b/examples/hotrod/services/frontend/server.go @@ -27,6 +27,7 @@ import ( "github.com/jaegertracing/jaeger/examples/hotrod/pkg/httperr" "github.com/jaegertracing/jaeger/examples/hotrod/pkg/log" + "github.com/jaegertracing/jaeger/examples/hotrod/pkg/tracing" "github.com/jaegertracing/jaeger/pkg/httpfs" ) @@ -36,7 +37,6 @@ var assetFS embed.FS // Server implements jaeger-demo-frontend service type Server struct { hostPort string - mux http.ServeMux tracer trace.TracerProvider logger log.Factory bestETA *bestETA @@ -73,17 +73,16 @@ func NewServer(options ConfigOptions, tracer trace.TracerProvider, logger log.Fa func (s *Server) Run() error { mux := s.createServeMux() s.logger.Bg().Info("Starting", zap.String("address", "http://"+path.Join(s.hostPort, s.basepath))) - return http.ListenAndServe(s.hostPort, otelhttp.NewHandler(mux, s.basepath, - otelhttp.WithTracerProvider(s.tracer))) + return http.ListenAndServe(s.hostPort, mux) } func (s *Server) createServeMux() http.Handler { - // mux := tracing.NewServeMux(true, s.tracer, s.logger) + mux := tracing.NewServeMux(true, s.tracer, s.logger) p := path.Join("/", s.basepath) - s.mux.Handle(p, otelhttp.WithRouteTag(p, http.StripPrefix(p, http.FileServer(s.assetFS)))) - s.mux.Handle(path.Join(p, "/dispatch"), otelhttp.WithRouteTag(path.Join(p, "/dispatch"), http.HandlerFunc(s.dispatch))) - s.mux.Handle(path.Join(p, "/config"), otelhttp.WithRouteTag(path.Join(p, "/config"), http.HandlerFunc(s.config))) - return &s.mux + mux.Handle(p, otelhttp.WithRouteTag(p, http.StripPrefix(p, http.FileServer(s.assetFS)))) + mux.Handle(path.Join(p, "/dispatch"), otelhttp.WithRouteTag(path.Join(p, "/dispatch"), http.HandlerFunc(s.dispatch))) + mux.Handle(path.Join(p, "/config"), otelhttp.WithRouteTag(path.Join(p, "/config"), http.HandlerFunc(s.config))) + return mux } func (s *Server) config(w http.ResponseWriter, r *http.Request) { diff --git a/examples/hotrod/services/route/server.go b/examples/hotrod/services/route/server.go index b93662b84f0..9d2643f9301 100644 --- a/examples/hotrod/services/route/server.go +++ b/examples/hotrod/services/route/server.go @@ -24,8 +24,8 @@ import ( "net/http" "time" - "github.com/opentracing/opentracing-go" "github.com/prometheus/client_golang/prometheus/promhttp" + "go.opentelemetry.io/otel/trace" "go.uber.org/zap" "github.com/jaegertracing/jaeger/examples/hotrod/pkg/delay" @@ -38,12 +38,12 @@ import ( // Server implements Route service type Server struct { hostPort string - tracer opentracing.Tracer + tracer trace.TracerProvider logger log.Factory } // NewServer creates a new route.Server -func NewServer(hostPort string, tracer opentracing.Tracer, logger log.Factory) *Server { +func NewServer(hostPort string, tracer trace.TracerProvider, logger log.Factory) *Server { return &Server{ hostPort: hostPort, tracer: tracer,