From 544ce2b4edd83e7cd21193269265be8dbc092aa1 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Wed, 23 Oct 2019 18:35:08 -0700 Subject: [PATCH] add peer to span and log (#3838) --- beacon-chain/sync/rpc.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/beacon-chain/sync/rpc.go b/beacon-chain/sync/rpc.go index 8e2d6b376..b801ae5bc 100644 --- a/beacon-chain/sync/rpc.go +++ b/beacon-chain/sync/rpc.go @@ -9,6 +9,7 @@ import ( "github.com/libp2p/go-libp2p-core/network" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/traceutil" "go.opencensus.io/trace" ) @@ -62,6 +63,8 @@ func (r *RegularSync) registerRPC(topic string, base interface{}, handle rpcHand ctx, span := trace.StartSpan(ctx, "sync.rpc") defer span.End() span.AddAttributes(trace.StringAttribute("topic", topic)) + span.AddAttributes(trace.StringAttribute("peer", stream.Conn().RemotePeer().Pretty())) + log := log.WithField("peer", stream.Conn().RemotePeer().Pretty()) if err := stream.SetReadDeadline(roughtime.Now().Add(ttfbTimeout)); err != nil { log.WithError(err).Error("Could not set stream read deadline") @@ -76,21 +79,25 @@ func (r *RegularSync) registerRPC(topic string, base interface{}, handle rpcHand msg := reflect.New(t.Elem()) if err := r.p2p.Encoding().DecodeWithLength(stream, msg.Interface()); err != nil { log.WithError(err).Error("Failed to decode stream message") + traceutil.AnnotateError(span, err) return } if err := handle(ctx, msg.Interface(), stream); err != nil { messageFailedProcessingCounter.WithLabelValues(topic).Inc() log.WithError(err).Error("Failed to handle p2p RPC") + traceutil.AnnotateError(span, err) } } else { msg := reflect.New(t) if err := r.p2p.Encoding().DecodeWithLength(stream, msg.Interface()); err != nil { log.WithError(err).Error("Failed to decode stream message") + traceutil.AnnotateError(span, err) return } if err := handle(ctx, msg.Elem().Interface(), stream); err != nil { messageFailedProcessingCounter.WithLabelValues(topic).Inc() log.WithError(err).Error("Failed to handle p2p RPC") + traceutil.AnnotateError(span, err) } }