Skip to content

Commit 86f7faf

Browse files
committed
allow to set trace verbosity and ttl
1 parent 1aba0a7 commit 86f7faf

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

ydb/core/viewer/json_pipe_req.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,24 @@ class TViewerPipeClient : public TActorBootstrapped<TDerived> {
135135
traceId = NWilson::TTraceId::FromTraceparentHeader(traceparent, TComponentTracingLevels::ProductionVerbose);
136136
}
137137
TStringBuf wantTrace = Event->Get()->Request.GetHeader("X-Want-Trace");
138-
if (!traceId && FromStringWithDefault<bool>(wantTrace)) {
139-
traceId = NWilson::TTraceId::NewTraceId(TComponentTracingLevels::ProductionVerbose, Max<ui32>());
138+
TStringBuf traceVerbosity = Event->Get()->Request.GetHeader("X-Trace-Verbosity");
139+
TStringBuf traceTTL = Event->Get()->Request.GetHeader("X-Trace-TTL");
140+
if (!traceId && (FromStringWithDefault<bool>(wantTrace) || !traceVerbosity.empty() || !traceTTL.empty())) {
141+
ui8 verbosity = TComponentTracingLevels::ProductionVerbose;
142+
if (traceVerbosity) {
143+
verbosity = FromStringWithDefault<ui8>(traceVerbosity, verbosity);
144+
if (verbosity > NWilson::TTraceId::MAX_VERBOSITY) {
145+
verbosity = NWilson::TTraceId::MAX_VERBOSITY;
146+
}
147+
}
148+
ui32 ttl = Max<ui32>();
149+
if (traceTTL) {
150+
ttl = FromStringWithDefault<ui32>(traceTTL, ttl);
151+
if (ttl > NWilson::TTraceId::MAX_TIME_TO_LIVE) {
152+
ttl = NWilson::TTraceId::MAX_TIME_TO_LIVE;
153+
}
154+
}
155+
traceId = NWilson::TTraceId::NewTraceId(verbosity, ttl);
140156
}
141157
if (traceId) {
142158
Span = {TComponentTracingLevels::THttp::TopLevel, std::move(traceId), "http", NWilson::EFlags::AUTO_END};

ydb/library/actors/wilson/wilson_trace.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@ namespace NWilson {
2626
ui32 Raw;
2727
};
2828

29+
public:
30+
static constexpr ui32 MAX_VERBOSITY = 15;
31+
static constexpr ui32 MAX_TIME_TO_LIVE = 4095;
32+
2933
private:
3034
TTraceId(TTrace traceId, ui64 spanId, ui8 verbosity, ui32 timeToLive)
3135
: TraceId(traceId)
3236
{
3337
if (timeToLive == Max<ui32>()) {
34-
timeToLive = 4095;
38+
timeToLive = MAX_TIME_TO_LIVE;
3539
}
36-
Y_ABORT_UNLESS(verbosity <= 15);
37-
Y_ABORT_UNLESS(timeToLive <= 4095);
40+
Y_ABORT_UNLESS(verbosity <= MAX_VERBOSITY);
41+
Y_ABORT_UNLESS(timeToLive <= MAX_TIME_TO_LIVE);
3842
SpanId = spanId;
3943
Verbosity = verbosity;
4044
TimeToLive = timeToLive;

0 commit comments

Comments
 (0)