5
5
6
6
#include < ydb/core/base/appdata.h>
7
7
8
+ #include < ydb/library/actors/wilson/wilson_span.h>
9
+ #include < ydb/library/wilson_ids/wilson.h>
10
+
8
11
#include < library/cpp/threading/future/future.h>
9
12
10
13
namespace NKikimr {
@@ -48,9 +51,12 @@ class TLocalRpcCtxImpl<TRpc, TCbWrapper, false> : public NGRpcService::IRequestN
48
51
using TBase = TLocalRpcCtxImplData<TRpc, TCbWrapper>;
49
52
50
53
template <typename TCb>
51
- TLocalRpcCtxImpl (TCb&& cb)
54
+ TLocalRpcCtxImpl (TCb&& cb, NWilson::TTraceId = {} )
52
55
: TBase(std::forward<TCb>(cb))
53
56
{}
57
+
58
+ protected:
59
+ NWilson::TSpan Span;
54
60
};
55
61
56
62
template <typename TRpc, typename TCbWrapper>
@@ -59,8 +65,9 @@ class TLocalRpcCtxImpl<TRpc, TCbWrapper, true> : public NGRpcService::IRequestOp
59
65
using TBase = TLocalRpcCtxImplData<TRpc, TCbWrapper>;
60
66
61
67
template <typename TCb>
62
- TLocalRpcCtxImpl (TCb&& cb)
68
+ TLocalRpcCtxImpl (TCb&& cb, NWilson::TTraceId traceId = {} )
63
69
: TBase(std::forward<TCb>(cb))
70
+ , Span(TWilsonGrpc::RequestProxy, std::move(traceId), " LocalRpc" )
64
71
{}
65
72
66
73
public:
@@ -77,6 +84,7 @@ class TLocalRpcCtxImpl<TRpc, TCbWrapper, true> : public NGRpcService::IRequestOp
77
84
NYql::IssuesToMessage (TBase::IssueManager.GetIssues (), deferred->mutable_issues ());
78
85
auto data = deferred->mutable_result ();
79
86
data->PackFrom (result);
87
+ EndSpan (status);
80
88
TBase::CbWrapper (resp);
81
89
}
82
90
@@ -93,14 +101,25 @@ class TLocalRpcCtxImpl<TRpc, TCbWrapper, true> : public NGRpcService::IRequestOp
93
101
}
94
102
auto data = deferred->mutable_result ();
95
103
data->PackFrom (result);
104
+ EndSpan (status);
96
105
TBase::CbWrapper (resp);
97
106
}
98
107
99
108
void SendOperation (const Ydb::Operations::Operation& operation) override {
100
109
TResp resp;
101
110
resp.mutable_operation ()->CopyFrom (operation);
111
+ EndSpan (operation.status ());
102
112
TBase::CbWrapper (resp);
103
113
}
114
+
115
+ protected:
116
+ void EndSpan (Ydb::StatusIds::StatusCode status) {
117
+ Span.Attribute (" status" , static_cast <int >(status));
118
+ Span.End ();
119
+ }
120
+
121
+ protected:
122
+ NWilson::TSpan Span;
104
123
};
105
124
106
125
template <typename TRpc, typename TCbWrapper, bool IsOperation = TRpc::IsOp>
@@ -116,8 +135,9 @@ class TLocalRpcCtx : public TLocalRpcCtxImpl<TRpc, TCbWrapper, IsOperation> {
116
135
const TString& databaseName,
117
136
const TMaybe<TString>& token,
118
137
const TMaybe<TString>& requestType,
119
- bool internalCall)
120
- : TBase(std::forward<TCb>(cb))
138
+ bool internalCall,
139
+ NWilson::TTraceId traceId = {})
140
+ : TBase(std::forward<TCb>(cb), std::move(traceId))
121
141
, Request(std::forward<TProto>(req))
122
142
, DatabaseName(databaseName)
123
143
, RequestType(requestType)
@@ -126,6 +146,11 @@ class TLocalRpcCtx : public TLocalRpcCtxImpl<TRpc, TCbWrapper, IsOperation> {
126
146
if (token && !token->empty ()) {
127
147
InternalToken = new NACLib::TUserToken (*token);
128
148
}
149
+
150
+ if (DatabaseName) {
151
+ this ->Span .Attribute (" database" , DatabaseName);
152
+ }
153
+ this ->Span .Attribute (" request_type" , GetRequestName ());
129
154
}
130
155
131
156
bool HasClientCapability (const TString&) const override {
@@ -226,7 +251,7 @@ class TLocalRpcCtx : public TLocalRpcCtxImpl<TRpc, TCbWrapper, IsOperation> {
226
251
}
227
252
228
253
NWilson::TTraceId GetWilsonTraceId () const override {
229
- return {} ;
254
+ return this -> Span . GetTraceId () ;
230
255
}
231
256
232
257
TInstant GetDeadline () const override {
@@ -301,14 +326,14 @@ void SetRequestSyncOperationMode(TRequest&) {
301
326
template <typename TRpc>
302
327
NThreading::TFuture<typename TRpc::TResponse> DoLocalRpc (typename TRpc::TRequest&& proto, const TString& database,
303
328
const TMaybe<TString>& token, const TMaybe<TString>& requestType,
304
- TActorSystem* actorSystem, bool internalCall = false )
329
+ TActorSystem* actorSystem, bool internalCall = false , NWilson::TTraceId traceId = {} )
305
330
{
306
331
auto promise = NThreading::NewPromise<typename TRpc::TResponse>();
307
332
308
333
SetRequestSyncOperationMode (proto);
309
334
310
335
using TCbWrapper = TPromiseWrapper<typename TRpc::TResponse>;
311
- auto req = new TLocalRpcCtx<TRpc, TCbWrapper>(std::move (proto), TCbWrapper (promise), database, token, requestType, internalCall);
336
+ auto req = new TLocalRpcCtx<TRpc, TCbWrapper>(std::move (proto), TCbWrapper (promise), database, token, requestType, internalCall, std::move (traceId) );
312
337
auto actor = TRpc::CreateRpcActor (req);
313
338
actorSystem->Register (actor, TMailboxType::HTSwap, actorSystem->AppData <TAppData>()->UserPoolId );
314
339
@@ -328,7 +353,8 @@ NThreading::TFuture<typename TRpc::TResponse> DoLocalRpc(
328
353
const TMaybe<TString>& requestType,
329
354
TActorSystem* actorSystem,
330
355
const TMap<TString, TString>& peerMeta,
331
- bool internalCall = false
356
+ bool internalCall = false ,
357
+ NWilson::TTraceId traceId = {}
332
358
)
333
359
{
334
360
auto promise = NThreading::NewPromise<typename TRpc::TResponse>();
@@ -342,7 +368,8 @@ NThreading::TFuture<typename TRpc::TResponse> DoLocalRpc(
342
368
database,
343
369
token,
344
370
requestType,
345
- internalCall
371
+ internalCall,
372
+ std::move (traceId)
346
373
);
347
374
348
375
for (const auto & [key, value] : peerMeta) {
@@ -358,18 +385,18 @@ NThreading::TFuture<typename TRpc::TResponse> DoLocalRpc(
358
385
template <typename TRpc>
359
386
TActorId DoLocalRpcSameMailbox (typename TRpc::TRequest&& proto, std::function<void (typename TRpc::TResponse)>&& cb,
360
387
const TString& database, const TMaybe<TString>& token, const TMaybe<TString>& requestType,
361
- const TActorContext& ctx, bool internalCall = false)
388
+ const TActorContext& ctx, bool internalCall = false, NWilson::TTraceId traceId = {} )
362
389
{
363
390
SetRequestSyncOperationMode (proto);
364
391
365
- auto req = new TLocalRpcCtx<TRpc, std::function<void (typename TRpc::TResponse)>>(std::move (proto), std::move (cb), database, token, requestType, internalCall);
392
+ auto req = new TLocalRpcCtx<TRpc, std::function<void (typename TRpc::TResponse)>>(std::move (proto), std::move (cb), database, token, requestType, internalCall, std::move (traceId) );
366
393
auto actor = TRpc::CreateRpcActor (req);
367
394
return ctx.RegisterWithSameMailbox (actor);
368
395
}
369
396
370
397
template <typename TRpc>
371
- TActorId DoLocalRpcSameMailbox (typename TRpc::TRequest&& proto, std::function<void (typename TRpc::TResponse)>&& cb, const TString& database, const TMaybe<TString>& token, const TActorContext& ctx, bool internalCall = false) {
372
- return DoLocalRpcSameMailbox<TRpc>(std::move (proto), std::move (cb), database, token, Nothing (), ctx, internalCall);
398
+ TActorId DoLocalRpcSameMailbox (typename TRpc::TRequest&& proto, std::function<void (typename TRpc::TResponse)>&& cb, const TString& database, const TMaybe<TString>& token, const TActorContext& ctx, bool internalCall = false, NWilson::TTraceId traceId = {} ) {
399
+ return DoLocalRpcSameMailbox<TRpc>(std::move (proto), std::move (cb), database, token, Nothing (), ctx, internalCall, std::move (traceId) );
373
400
}
374
401
375
402
// // Streaming part
0 commit comments