aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozhikhov <akozhikhov@yandex-team.com>2024-06-20 00:30:28 +0300
committerakozhikhov <akozhikhov@yandex-team.com>2024-06-20 00:39:55 +0300
commit10ee00c96ea853958790895d65a40b0286f8ea4a (patch)
treeecb8bb38d7ed12f1e4de9e881eabdb733d48a2a5
parent4ccb78569fa336d5a57cb2d8f880013cfc2ba6fa (diff)
downloadydb-10ee00c96ea853958790895d65a40b0286f8ea4a.tar.gz
Add trace_id to bus/channel errors
8bfa6225c3741285aa4de52a1b33dbff27ae3553
-rw-r--r--yt/yt/core/misc/error.cpp16
-rw-r--r--yt/yt/core/misc/error.h1
-rw-r--r--yt/yt/core/rpc/bus/channel.cpp16
-rw-r--r--yt/yt/core/tracing/public.h2
-rw-r--r--yt/yt/core/tracing/trace_context.cpp23
-rw-r--r--yt/yt/core/tracing/trace_context.h23
6 files changed, 68 insertions, 13 deletions
diff --git a/yt/yt/core/misc/error.cpp b/yt/yt/core/misc/error.cpp
index 2e63016b86f..bd27f1769a4 100644
--- a/yt/yt/core/misc/error.cpp
+++ b/yt/yt/core/misc/error.cpp
@@ -210,6 +210,14 @@ public:
return TraceId_ != NTracing::InvalidTraceId;
}
+ void SetTracingAttributes(NTracing::TTracingAttributes tracingAttributes)
+ {
+ YT_VERIFY(!HasTracingAttributes());
+
+ TraceId_ = tracingAttributes.TraceId;
+ SpanId_ = tracingAttributes.SpanId;
+ }
+
NTracing::TTraceId GetTraceId() const
{
return TraceId_;
@@ -626,6 +634,14 @@ bool TError::HasTracingAttributes() const
return Impl_->HasTracingAttributes();
}
+void TError::SetTracingAttributes(NTracing::TTracingAttributes tracingAttributes)
+{
+ if (!Impl_) {
+ return;
+ }
+ Impl_->SetTracingAttributes(tracingAttributes);
+}
+
NTracing::TTraceId TError::GetTraceId() const
{
if (!Impl_) {
diff --git a/yt/yt/core/misc/error.h b/yt/yt/core/misc/error.h
index 0fb97e5c819..4eb7d154751 100644
--- a/yt/yt/core/misc/error.h
+++ b/yt/yt/core/misc/error.h
@@ -166,6 +166,7 @@ public:
TInstant GetDatetime() const;
bool HasTracingAttributes() const;
+ void SetTracingAttributes(NTracing::TTracingAttributes tracingAttributes);
NTracing::TTraceId GetTraceId() const;
NTracing::TSpanId GetSpanId() const;
diff --git a/yt/yt/core/rpc/bus/channel.cpp b/yt/yt/core/rpc/bus/channel.cpp
index a88a995b872..6eb01abd106 100644
--- a/yt/yt/core/rpc/bus/channel.cpp
+++ b/yt/yt/core/rpc/bus/channel.cpp
@@ -21,6 +21,8 @@
#include <yt/yt/core/misc/finally.h>
#include <yt/yt/core/misc/atomic_object.h>
+#include <yt/yt/core/tracing/public.h>
+
#include <yt/yt_proto/yt/core/rpc/proto/rpc.pb.h>
#include <library/cpp/yt/threading/rw_spin_lock.h>
@@ -33,10 +35,11 @@
namespace NYT::NRpc::NBus {
using namespace NYT::NBus;
+using namespace NConcurrency;
+using namespace NTracing;
using namespace NYPath;
using namespace NYTree;
using namespace NYson;
-using namespace NConcurrency;
using NYT::FromProto;
using NYT::ToProto;
@@ -1094,6 +1097,12 @@ private:
<< TErrorAttribute("timeout", *requestControl->GetTimeout());
}
+ if (!detailedError.HasTracingAttributes()) {
+ if (auto tracingAttributes = requestControl->GetTracingAttributes()) {
+ detailedError.SetTracingAttributes(*tracingAttributes);
+ }
+ }
+
YT_LOG_DEBUG(detailedError, "%v (RequestId: %v)",
reason,
requestControl->GetRequestId());
@@ -1189,6 +1198,11 @@ private:
return TraceContext_.MakeTraceContextGuard();
}
+ std::optional<TTracingAttributes> GetTracingAttributes() const
+ {
+ return TraceContext_.GetTracingAttributes();
+ }
+
template <typename TLock>
bool IsActive(const TGuard<TLock>&) const
{
diff --git a/yt/yt/core/tracing/public.h b/yt/yt/core/tracing/public.h
index 6ced43f6b8e..9d864133aab 100644
--- a/yt/yt/core/tracing/public.h
+++ b/yt/yt/core/tracing/public.h
@@ -26,6 +26,8 @@ constexpr TTraceId InvalidTraceId = {};
using TSpanId = ui64;
constexpr TSpanId InvalidSpanId = 0;
+struct TTracingAttributes;
+
// Request ids come from RPC infrastructure but
// we should avoid include-dependencies here.
using TRequestId = TGuid;
diff --git a/yt/yt/core/tracing/trace_context.cpp b/yt/yt/core/tracing/trace_context.cpp
index 385dde55463..23a7f1e3b14 100644
--- a/yt/yt/core/tracing/trace_context.cpp
+++ b/yt/yt/core/tracing/trace_context.cpp
@@ -727,6 +727,29 @@ Y_NO_INLINE TTraceContext* TryGetTraceContextFromPropagatingStorage(const NConcu
////////////////////////////////////////////////////////////////////////////////
+TTraceContextHandler::TTraceContextHandler()
+ : TraceContext_(NTracing::TryGetCurrentTraceContext())
+{ }
+
+NTracing::TCurrentTraceContextGuard TTraceContextHandler::MakeTraceContextGuard() const
+{
+ return NTracing::TCurrentTraceContextGuard(TraceContext_);
+}
+
+void TTraceContextHandler::UpdateTraceContext()
+{
+ TraceContext_ = NTracing::TryGetCurrentTraceContext();
+}
+
+std::optional<TTracingAttributes> TTraceContextHandler::GetTracingAttributes() const
+{
+ return TraceContext_
+ ? std::make_optional<TTracingAttributes>(TraceContext_->GetTraceId(), TraceContext_->GetSpanId())
+ : std::nullopt;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
} // namespace NYT::NTracing
namespace NYT::NYTProf {
diff --git a/yt/yt/core/tracing/trace_context.h b/yt/yt/core/tracing/trace_context.h
index 366aabb2be9..fba81410811 100644
--- a/yt/yt/core/tracing/trace_context.h
+++ b/yt/yt/core/tracing/trace_context.h
@@ -21,6 +21,12 @@ namespace NYT::NTracing {
////////////////////////////////////////////////////////////////////////////////
+struct TTracingAttributes
+{
+ TTraceId TraceId = InvalidTraceId;
+ TSpanId SpanId = InvalidSpanId;
+};
+
//! TSpanContext represents span identity propagated across the network.
//!
//! See https://opentracing.io/specification/
@@ -399,23 +405,16 @@ void AnnotateTraceContext(TFn&& fn);
////////////////////////////////////////////////////////////////////////////////
-// TODO(babenko): move impl to cpp.
class TTraceContextHandler
{
public:
- TTraceContextHandler()
- : TraceContext_(NTracing::TryGetCurrentTraceContext())
- { }
+ TTraceContextHandler();
- NTracing::TCurrentTraceContextGuard MakeTraceContextGuard() const
- {
- return NTracing::TCurrentTraceContextGuard(TraceContext_);
- }
+ NTracing::TCurrentTraceContextGuard MakeTraceContextGuard() const;
- void UpdateTraceContext()
- {
- TraceContext_ = NTracing::TryGetCurrentTraceContext();
- }
+ void UpdateTraceContext();
+
+ std::optional<TTracingAttributes> GetTracingAttributes() const;
private:
NTracing::TTraceContextPtr TraceContext_;