net: Rework CNode spans

- Extract a reload function for recreating them.
- Record the peer id.
- Remove the peer id and address from the CNode constructor log
  (it will always be shown by the span at that log level).
This commit is contained in:
Jack Grigg 2020-12-16 01:37:17 +00:00
parent e9cc9b4eec
commit 42c38b00c1
2 changed files with 23 additions and 11 deletions

View File

@ -2109,22 +2109,16 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa
fPingQueued = false;
nMinPingUsecTime = std::numeric_limits<int64_t>::max();
if (fLogIPs) {
span = TracingSpanFields("info", "net", "CNode", "addr", addrName.c_str());
} else {
span = TracingSpan("info", "net", "CNode");
}
auto spanGuard = span.Enter();
{
LOCK(cs_nLastNodeId);
id = nLastNodeId++;
}
idStr = tfm::format("%d", id);
if (fLogIPs)
LogPrint("net", "Added connection to %s peer=%d\n", addrName, id);
else
LogPrint("net", "Added connection peer=%d\n", id);
ReloadTracingSpan();
auto spanGuard = span.Enter();
LogPrint("net", "Added connection");
// Be shy and don't send version until we hear
if (hSocket != INVALID_SOCKET && !fInbound)
@ -2143,6 +2137,18 @@ CNode::~CNode()
GetNodeSignals().FinalizeNode(GetId());
}
void CNode::ReloadTracingSpan()
{
if (fLogIPs) {
span = TracingSpanFields("info", "net", "Peer",
"id", idStr.c_str(),
"addr", addrName.c_str());
} else {
span = TracingSpanFields("info", "net", "Peer",
"id", idStr.c_str());
}
}
void CNode::AskFor(const CInv& inv)
{
if (mapAskFor.size() > MAPASKFOR_MAX_SZ || setAskFor.size() > SETASKFOR_MAX_SZ)

View File

@ -298,6 +298,8 @@ public:
CBloomFilter* pfilter;
int nRefCount;
NodeId id;
// Stored so we can pass a pointer to it across the Rust FFI for span.
std::string idStr;
tracing::Span span;
protected:
@ -359,6 +361,10 @@ private:
public:
// Regenerate the span for this CNode. This re-queries the log filter to see
// if the span should be enabled, and re-collects the logged variables.
void ReloadTracingSpan();
NodeId GetId() const {
return id;
}