server: avoid call to trace.FromContext and resulting allocations when tracing is disabled (#2926)

This commit is contained in:
David Zbarsky
2019-07-30 13:14:53 -04:00
committed by Doug Fawley
parent a4f24690a4
commit 92635fa6bf

View File

@ -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