Skip to content

Commit e58b6f6

Browse files
authored
add traces to http backend (#5874)
1 parent b15d3d7 commit e58b6f6

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

ydb/core/viewer/json_pipe_req.h

+17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <ydb/library/actors/core/actor.h>
44
#include <ydb/library/actors/core/actor_bootstrapped.h>
5+
#include <ydb/library/wilson_ids/wilson.h>
6+
#include <ydb/library/actors/wilson/wilson_span.h>
57
#include <ydb/core/base/tablet_pipe.h>
68
#include <ydb/core/cms/console/console.h>
79
#include <ydb/core/base/hive.h>
@@ -31,6 +33,7 @@ class TViewerPipeClient : public TActorBootstrapped<TDerived> {
3133
bool WithRetry = true;
3234
ui32 Requests = 0;
3335
static constexpr ui32 MaxRequestsInFlight = 50;
36+
NWilson::TSpan Span;
3437

3538
struct TPipeInfo {
3639
TActorId PipeClient;
@@ -53,6 +56,20 @@ class TViewerPipeClient : public TActorBootstrapped<TDerived> {
5356
return clientConfig;
5457
}
5558

59+
TViewerPipeClient() = default;
60+
61+
TViewerPipeClient(NMon::TEvHttpInfo::TPtr& ev) {
62+
InitConfig(ev->Get()->Request.GetParams());
63+
TStringBuf traceparent = ev->Get()->Request.GetHeader("traceparent");
64+
if (traceparent) {
65+
NWilson::TTraceId traceId = NWilson::TTraceId::FromTraceparentHeader(traceparent, TComponentTracingLevels::ProductionVerbose);
66+
if (traceId) {
67+
Span = {TComponentTracingLevels::THttp::TopLevel, std::move(traceId), "http", NWilson::EFlags::AUTO_END};
68+
Span.Attribute("request_type", TString(ev->Get()->Request.GetPathInfo()));
69+
}
70+
}
71+
}
72+
5673
TActorId ConnectTabletPipe(NNodeWhiteboard::TTabletId tabletId) {
5774
TPipeInfo& pipeInfo = PipeInfo[tabletId];
5875
if (!pipeInfo.PipeClient) {

ydb/core/viewer/json_query.h

+21-6
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
106106
}
107107

108108
TJsonQuery(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev)
109-
: Viewer(viewer)
109+
: TBase(ev)
110+
, Viewer(viewer)
110111
, Event(ev)
111112
{
112113
}
@@ -193,6 +194,9 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
193194
auto event = std::make_unique<NKqp::TEvKqp::TEvCreateSessionRequest>();
194195
if (Database) {
195196
event->Record.MutableRequest()->SetDatabase(Database);
197+
if (Span) {
198+
Span.Attribute("database", Database);
199+
}
196200
}
197201
BLOG_TRACE("Creating session");
198202
Send(NKqp::MakeKqpProxyID(SelfId().NodeId()), event.release());
@@ -440,6 +444,9 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
440444

441445
void ReplyAndPassAway(TString data) {
442446
Send(Event->Sender, new NMon::TEvHttpInfoRes(data, 0, NMon::IEvHttpInfoRes::EContentType::Custom));
447+
if (Span) {
448+
Span.End();
449+
}
443450
PassAway();
444451
}
445452

@@ -454,14 +461,19 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
454461
while (protoIssues->size() > 0 && (*protoIssues)[0].issuesSize() > 0) {
455462
protoIssues = (*protoIssues)[0].mutable_issues();
456463
}
464+
TString message;
457465
if (protoIssues->size() > 0) {
458466
const Ydb::Issue::IssueMessage& issue = (*protoIssues)[0];
459467
NProtobufJson::Proto2Json(issue, jsonResponse["error"]);
468+
message = issue.message();
460469
}
461470
for (const auto& queryIssue : *protoIssues) {
462471
NJson::TJsonValue& issue = jsonIssues.AppendValue({});
463472
NProtobufJson::Proto2Json(queryIssue, issue);
464473
}
474+
if (Span) {
475+
Span.EndError(message);
476+
}
465477
}
466478

467479
void MakeOkReply(NJson::TJsonValue& jsonResponse, NKikimrKqp::TEvQueryResponse& record) {
@@ -591,6 +603,9 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
591603
if (response.HasQueryStats()) {
592604
NProtobufJson::Proto2Json(response.GetQueryStats(), jsonResponse["stats"]);
593605
}
606+
if (Span) {
607+
Span.EndOk();
608+
}
594609
}
595610
};
596611

@@ -619,6 +634,11 @@ YAML::Node TJsonRequestSwagger<TJsonQuery>::GetSwagger() {
619634
* `explain-scan` - explain scan query (ScanQuery)
620635
* `explain-script` - explain script query (ScriptingService)
621636
* `cancel-query` - cancel query (using query_id)
637+
- name: database
638+
in: query
639+
description: database name
640+
type: string
641+
required: false
622642
- name: query
623643
in: query
624644
description: SQL query text
@@ -637,11 +657,6 @@ YAML::Node TJsonRequestSwagger<TJsonQuery>::GetSwagger() {
637657
type: string
638658
enum: [yql_v1, pg]
639659
required: false
640-
- name: database
641-
in: query
642-
description: database name
643-
type: string
644-
required: false
645660
- name: schema
646661
in: query
647662
description: >

ydb/library/wilson_ids/wilson.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace NKikimr {
2020
};
2121

2222

23+
DEFINE_TRACING_LEVELS(THttp, 0, 5, 10, 14, 15)
2324
DEFINE_TRACING_LEVELS(TGrpcProxy, 0, 5, 10, 14, 15)
2425
DEFINE_TRACING_LEVELS(TQueryProcessor, 1, 6, 10, 14, 15)
2526
DEFINE_TRACING_LEVELS(TDistributedTransactions, 2, 7, 11, 14, 15)
@@ -77,7 +78,7 @@ namespace NKikimr {
7778

7879
LookupActor = TComponentTracingLevels::TQueryProcessor::Basic,
7980
LookupActorShardsResolve = TComponentTracingLevels::TQueryProcessor::Detailed,
80-
81+
8182
BulkUpsertActor = TComponentTracingLevels::TQueryProcessor::TopLevel,
8283
};
8384
};

0 commit comments

Comments
 (0)