Skip to content

Commit

Permalink
KIKIMR-20042 Wilson enchancements (ydb-platform#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
domwst authored and CyberROFL committed Dec 19, 2023
1 parent 584b9d1 commit 2f16d0d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
4 changes: 1 addition & 3 deletions ydb/library/actors/wilson/wilson_span.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ namespace NWilson {
}

void TSpan::Send() {
if (TlsActivationContext) {
TActivationContext::Send(new IEventHandle(MakeWilsonUploaderId(), {}, new TEvWilson(&Data->Span)));
}
Data->ActorSystem->Send(new IEventHandle(MakeWilsonUploaderId(), {}, new TEvWilson(&Data->Span)));
Data->Sent = true;
}

Expand Down
22 changes: 17 additions & 5 deletions ydb/library/actors/wilson/wilson_span.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ namespace NWilson {
int UncaughtExceptions = std::uncaught_exceptions();
bool Sent = false;
bool Ignored = false;
NActors::TActorSystem* ActorSystem;

TData(TInstant startTime, ui64 startCycles, TTraceId traceId, TFlags flags)
TData(TInstant startTime, ui64 startCycles, TTraceId traceId, TFlags flags, NActors::TActorSystem* actorSystem)
: StartTime(startTime)
, StartCycles(startCycles)
, TraceId(std::move(traceId))
, Flags(flags)
{}
, ActorSystem(actorSystem != nullptr ? actorSystem : (NActors::TlsActivationContext ? NActors::TActivationContext::ActorSystem() : nullptr))
{
Y_ABORT_UNLESS(ActorSystem != nullptr, "Attempting to create NWilson::TSpan outside of actor system without providing actorSystem pointer");
}

~TData() {
Y_DEBUG_ABORT_UNLESS(Sent || Ignored);
Expand All @@ -76,9 +80,9 @@ namespace NWilson {
TSpan(const TSpan&) = delete;
TSpan(TSpan&&) = default;

TSpan(ui8 verbosity, TTraceId parentId, std::optional<TString> name, TFlags flags = EFlags::NONE)
TSpan(ui8 verbosity, TTraceId parentId, std::optional<TString> name, TFlags flags = EFlags::NONE, NActors::TActorSystem* actorSystem = nullptr)
: Data(parentId
? std::make_unique<TData>(TInstant::Now(), GetCycleCount(), parentId.Span(verbosity), flags)
? std::make_unique<TData>(TInstant::Now(), GetCycleCount(), parentId.Span(verbosity), flags, actorSystem)
: nullptr)
{
if (Y_UNLIKELY(*this)) {
Expand All @@ -93,7 +97,7 @@ namespace NWilson {
Name(std::move(*name));
}

Attribute("node_id", NActors::TActivationContext::ActorSystem()->NodeId);
Attribute("node_id", Data->ActorSystem->NodeId);
} else {
Data->Ignored = true; // ignore this span due to verbosity mismatch, still allowing child spans to be created
}
Expand Down Expand Up @@ -228,6 +232,14 @@ namespace NWilson {
return Data ? TTraceId(Data->TraceId) : TTraceId();
}

NActors::TActorSystem* GetActorSystem() const {
return Data ? Data->ActorSystem : nullptr;
}

TSpan CreateChild(ui8 verbosity, std::optional<TString> name, TFlags flags = EFlags::NONE) const {
return TSpan(verbosity, GetTraceId(), std::move(name), flags, GetActorSystem());
}

private:
void Send();

Expand Down
5 changes: 5 additions & 0 deletions ydb/library/actors/wilson/wilson_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <util/random/random.h>
#include <util/random/fast.h>

#include <util/string/hex.h>
#include <util/string/printf.h>

#include <array>
Expand Down Expand Up @@ -222,6 +223,10 @@ namespace NWilson {
const void *GetSpanIdPtr() const { return &SpanId; }
static constexpr size_t GetSpanIdSize() { return sizeof(ui64); }

TString GetHexTraceId() const {
return HexEncode(GetTraceIdPtr(), GetTraceIdSize());
}

void Validate() const {
Y_DEBUG_ABORT_UNLESS(*this || !SpanId);
}
Expand Down

0 comments on commit 2f16d0d

Please sign in to comment.