From 92635fa6bffd9db9b2cca8ce8f978bfebabd9c29 Mon Sep 17 00:00:00 2001 From: David Zbarsky Date: Tue, 30 Jul 2019 13:14:53 -0400 Subject: [PATCH] server: avoid call to trace.FromContext and resulting allocations when tracing is disabled (#2926) --- server.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server.go b/server.go index 3d482dba5..f064b73e5 100644 --- a/server.go +++ b/server.go @@ -761,6 +761,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { // traceInfo returns a traceInfo and associates it with stream, if tracing is enabled. // If tracing is not enabled, it returns nil. func (s *Server) traceInfo(st transport.ServerTransport, stream *transport.Stream) (trInfo *traceInfo) { + if !EnableTracing { + return nil + } tr, ok := trace.FromContext(stream.Context()) if !ok { return nil