Skip to content

Commit

Permalink
server: Only call FromIncomingContext with stats handlers (#7781)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanj authored Oct 29, 2024
1 parent 192ee33 commit 091d20b
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1783,17 +1783,20 @@ func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Str
service := sm[:pos]
method := sm[pos+1:]

md, _ := metadata.FromIncomingContext(ctx)
for _, sh := range s.opts.statsHandlers {
ctx = sh.TagRPC(ctx, &stats.RPCTagInfo{FullMethodName: stream.Method()})
sh.HandleRPC(ctx, &stats.InHeader{
FullMethod: stream.Method(),
RemoteAddr: t.Peer().Addr,
LocalAddr: t.Peer().LocalAddr,
Compression: stream.RecvCompress(),
WireLength: stream.HeaderWireLength(),
Header: md,
})
// FromIncomingContext is expensive: skip if there are no statsHandlers
if len(s.opts.statsHandlers) > 0 {
md, _ := metadata.FromIncomingContext(ctx)
for _, sh := range s.opts.statsHandlers {
ctx = sh.TagRPC(ctx, &stats.RPCTagInfo{FullMethodName: stream.Method()})
sh.HandleRPC(ctx, &stats.InHeader{
FullMethod: stream.Method(),
RemoteAddr: t.Peer().Addr,
LocalAddr: t.Peer().LocalAddr,
Compression: stream.RecvCompress(),
WireLength: stream.HeaderWireLength(),
Header: md,
})
}
}
// To have calls in stream callouts work. Will delete once all stats handler
// calls come from the gRPC layer.
Expand Down

0 comments on commit 091d20b

Please sign in to comment.