Skip to content

Commit cb3fa36

Browse files
committed
feat httpclient, grpc client: add span tags for service map
commit_hash:e869d778a6d23b1f39eb4718d7e8df5b016be0a2
1 parent 4e43519 commit cb3fa36

File tree

8 files changed

+17
-9
lines changed

8 files changed

+17
-9
lines changed

core/include/userver/clients/http/plugin.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
USERVER_NAMESPACE_BEGIN
1313

14+
namespace tracing {
15+
class Span;
16+
}
17+
1418
namespace clients::http {
1519

1620
class RequestState;
@@ -51,7 +55,7 @@ class Plugin {
5155

5256
/// @brief The hook is called just after the "external" Span is created.
5357
/// You might want to add custom tags from the hook.
54-
virtual void HookCreateSpan(PluginRequest& request) = 0;
58+
virtual void HookCreateSpan(PluginRequest& request, tracing::Span& span) = 0;
5559

5660
/// @brief The hook is called after the HTTP response is received or the
5761
/// timeout is passed.
@@ -72,7 +76,7 @@ class PluginPipeline final {
7276

7377
void HookPerformRequest(RequestState& request);
7478

75-
void HookCreateSpan(RequestState& request);
79+
void HookCreateSpan(RequestState& request, tracing::Span& span);
7680

7781
void HookOnCompleted(RequestState& request, Response& response);
7882

core/src/clients/http/plugin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ namespace impl {
3838

3939
PluginPipeline::PluginPipeline(const std::vector<utils::NotNull<Plugin*>>& plugins) : plugins_(plugins) {}
4040

41-
void PluginPipeline::HookCreateSpan(RequestState& request_state) {
41+
void PluginPipeline::HookCreateSpan(RequestState& request_state, tracing::Span& span) {
4242
PluginRequest req(request_state);
4343

4444
for (const auto& plugin : plugins_) {
45-
plugin->HookCreateSpan(req);
45+
plugin->HookCreateSpan(req, span);
4646
}
4747
}
4848

core/src/clients/http/plugins/headers_propagator/plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Plugin::Plugin() : clients::http::Plugin(kName) {}
1515

1616
void Plugin::HookPerformRequest(PluginRequest&) {}
1717

18-
void Plugin::HookCreateSpan(PluginRequest& request) {
18+
void Plugin::HookCreateSpan(PluginRequest& request, tracing::Span&) {
1919
for (const auto& [name, value] : server::request::GetPropagatedHeaders()) {
2020
request.SetHeader(name, value);
2121
}

core/src/clients/http/plugins/headers_propagator/plugin.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Plugin final : public http::Plugin {
1212

1313
void HookPerformRequest(PluginRequest&) override;
1414

15-
void HookCreateSpan(PluginRequest&) override;
15+
void HookCreateSpan(PluginRequest&, tracing::Span& span) override;
1616

1717
void HookOnCompleted(PluginRequest&, Response&) override;
1818

core/src/clients/http/plugins/yandex_tracing/plugin.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <userver/clients/http/response.hpp>
44
#include <userver/logging/log.hpp>
5+
#include <userver/tracing/span.hpp>
56
#include <userver/utils/algo.hpp>
67

78
#include <userver/http/common_headers.hpp>
@@ -18,13 +19,15 @@ constexpr USERVER_NAMESPACE::http::headers::PredefinedHeader kYaTracingHeaders[]
1819
};
1920

2021
const std::string kName = "yandex-tracing";
22+
const std::string kTypeTag = "type";
23+
const std::string kTypeRequest = "request";
2124
} // namespace
2225

2326
Plugin::Plugin() : http::Plugin(kName) {}
2427

2528
void Plugin::HookPerformRequest(PluginRequest&) {}
2629

27-
void Plugin::HookCreateSpan(PluginRequest&) {}
30+
void Plugin::HookCreateSpan(PluginRequest&, tracing::Span& span) { span.AddNonInheritableTag(kTypeTag, kTypeRequest); }
2831

2932
void Plugin::HookOnCompleted(PluginRequest&, Response& response) {
3033
const auto& headers = response.headers();

core/src/clients/http/plugins/yandex_tracing/plugin.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Plugin final : public http::Plugin {
1212

1313
void HookPerformRequest(PluginRequest& request) override;
1414

15-
void HookCreateSpan(PluginRequest& request) override;
15+
void HookCreateSpan(PluginRequest& request, tracing::Span& span) override;
1616

1717
void HookOnCompleted(PluginRequest& request, Response& response) override;
1818
};

core/src/clients/http/request_state.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ void RequestState::StartNewSpan(utils::impl::SourceLocation location) {
974974
auto request_editable_instance = GetEditableRequestInstance();
975975

976976
tracing_manager_->FillRequestWithTracingContext(span, request_editable_instance);
977-
plugin_pipeline_.HookCreateSpan(*this);
977+
plugin_pipeline_.HookCreateSpan(*this, span);
978978
span.AddTag(tracing::kHttpUrl, GetLoggedOriginalUrl());
979979
span.AddTag(tracing::kMaxAttempts, retry_.retries);
980980

grpc/src/ugrpc/client/middlewares/log/middleware.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void Middleware::PreStartCall(MiddlewareCallContext& context) const {
4444
span.SetLocalLogLevel(settings_.log_level);
4545

4646
span.AddTag("meta_type", std::string{context.GetCallName()});
47+
span.AddTag("type", "request");
4748

4849
if (!IsSingleRequest(context.GetCallKind())) {
4950
SpanLogger{context.GetSpan(), settings_.log_level}.Log(

0 commit comments

Comments
 (0)