Skip to content

Commit 32dffc3

Browse files
authored
KIKIMR-20042 Wilson enchancements (#540)
1 parent 31e4848 commit 32dffc3

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

ydb/library/actors/wilson/wilson_span.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ namespace NWilson {
5353
}
5454

5555
void TSpan::Send() {
56-
if (TlsActivationContext) {
57-
TActivationContext::Send(new IEventHandle(MakeWilsonUploaderId(), {}, new TEvWilson(&Data->Span)));
58-
}
56+
Data->ActorSystem->Send(new IEventHandle(MakeWilsonUploaderId(), {}, new TEvWilson(&Data->Span)));
5957
Data->Sent = true;
6058
}
6159

ydb/library/actors/wilson/wilson_span.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@ namespace NWilson {
5656
int UncaughtExceptions = std::uncaught_exceptions();
5757
bool Sent = false;
5858
bool Ignored = false;
59+
NActors::TActorSystem* ActorSystem;
5960

60-
TData(TInstant startTime, ui64 startCycles, TTraceId traceId, TFlags flags)
61+
TData(TInstant startTime, ui64 startCycles, TTraceId traceId, TFlags flags, NActors::TActorSystem* actorSystem)
6162
: StartTime(startTime)
6263
, StartCycles(startCycles)
6364
, TraceId(std::move(traceId))
6465
, Flags(flags)
65-
{}
66+
, ActorSystem(actorSystem != nullptr ? actorSystem : (NActors::TlsActivationContext ? NActors::TActivationContext::ActorSystem() : nullptr))
67+
{
68+
Y_ABORT_UNLESS(ActorSystem != nullptr, "Attempting to create NWilson::TSpan outside of actor system without providing actorSystem pointer");
69+
}
6670

6771
~TData() {
6872
Y_DEBUG_ABORT_UNLESS(Sent || Ignored);
@@ -76,9 +80,9 @@ namespace NWilson {
7680
TSpan(const TSpan&) = delete;
7781
TSpan(TSpan&&) = default;
7882

79-
TSpan(ui8 verbosity, TTraceId parentId, std::optional<TString> name, TFlags flags = EFlags::NONE)
83+
TSpan(ui8 verbosity, TTraceId parentId, std::optional<TString> name, TFlags flags = EFlags::NONE, NActors::TActorSystem* actorSystem = nullptr)
8084
: Data(parentId
81-
? std::make_unique<TData>(TInstant::Now(), GetCycleCount(), parentId.Span(verbosity), flags)
85+
? std::make_unique<TData>(TInstant::Now(), GetCycleCount(), parentId.Span(verbosity), flags, actorSystem)
8286
: nullptr)
8387
{
8488
if (Y_UNLIKELY(*this)) {
@@ -93,7 +97,7 @@ namespace NWilson {
9397
Name(std::move(*name));
9498
}
9599

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

235+
NActors::TActorSystem* GetActorSystem() const {
236+
return Data ? Data->ActorSystem : nullptr;
237+
}
238+
239+
TSpan CreateChild(ui8 verbosity, std::optional<TString> name, TFlags flags = EFlags::NONE) const {
240+
return TSpan(verbosity, GetTraceId(), std::move(name), flags, GetActorSystem());
241+
}
242+
231243
private:
232244
void Send();
233245

ydb/library/actors/wilson/wilson_trace.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <util/random/random.h>
1010
#include <util/random/fast.h>
1111

12+
#include <util/string/hex.h>
1213
#include <util/string/printf.h>
1314

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

226+
TString GetHexTraceId() const {
227+
return HexEncode(GetTraceIdPtr(), GetTraceIdSize());
228+
}
229+
225230
void Validate() const {
226231
Y_DEBUG_ABORT_UNLESS(*this || !SpanId);
227232
}

0 commit comments

Comments
 (0)