diff --git a/deps/oblib/src/lib/trace/ob_trace.cpp b/deps/oblib/src/lib/trace/ob_trace.cpp index 01edf57b7..16499f8e2 100644 --- a/deps/oblib/src/lib/trace/ob_trace.cpp +++ b/deps/oblib/src/lib/trace/ob_trace.cpp @@ -413,6 +413,7 @@ ObSpanCtx* ObTrace::begin_span(uint32_t span_type, uint8_t level, bool is_follow new_span = freed_span_.remove_last(); current_span_.add_first(new_span); new_span->span_type_ = span_type; + new_span->span_id_.high_ = 0; new_span->span_id_.low_ = ++seq_; new_span->span_id_.high_ = 0; new_span->source_span_ = last_active_span_; diff --git a/deps/oblib/src/lib/trace/ob_trace.h b/deps/oblib/src/lib/trace/ob_trace.h index 989e4d85d..9b09efbbe 100644 --- a/deps/oblib/src/lib/trace/ob_trace.h +++ b/deps/oblib/src/lib/trace/ob_trace.h @@ -28,7 +28,7 @@ #define FLT_END_SPAN(span) \ if (OB_NOT_NULL(span)) { \ OBTRACE->end_span(span); \ - if (span->span_id_.is_inited() && OBTRACE->is_auto_flush()) { \ + if (span->is_inited() && OBTRACE->is_auto_flush()) { \ FLUSH_TRACE(); \ } \ } @@ -126,6 +126,7 @@ public: struct ObTagCtxBase { + friend void flush_trace(); ObTagCtxBase() : next_(nullptr), tag_type_(0) {} virtual ~ObTagCtxBase() {} virtual int tostring(char* buf, const int64_t buf_len, int64_t& pos) @@ -146,6 +147,7 @@ struct ObTagCtxBase } return ret; } +protected: ObTagCtxBase* next_; uint16_t tag_type_; }; @@ -186,6 +188,7 @@ int tag_to_string(char* buf, const int64_t buf_len, int64_t& pos, const T& value template struct ObTagCtx final : public ObTagCtxBase { + friend struct ObTrace; ObTagCtx() {} virtual ~ObTagCtx() override {} virtual int tostring(char* buf, const int64_t buf_len, int64_t& pos) override @@ -198,13 +201,18 @@ struct ObTagCtx final : public ObTagCtxBase } return ret; } +private: T data_; }; struct ObSpanCtx final : public common::ObDLinkBase { + friend struct ObTrace; + friend void flush_trace(); +public: ObSpanCtx(); - + OB_INLINE bool is_inited() const { return span_id_.is_inited(); } + UUID get_span_id() const { return span_id_; } UUID span_id_; ObSpanCtx* source_span_; int64_t start_ts_; @@ -348,7 +356,7 @@ public: { span_ = OBTRACE->begin_span(span_type, level, false); #ifndef NDEBUG - if (OB_NOT_NULL(span_) && span_->span_id_.is_inited()) { + if (OB_NOT_NULL(span_) && span_->is_inited()) { FLT_SET_TAG(span_back_trace, lbt()); } #endif diff --git a/deps/oblib/unittest/lib/trace/test_trace.cpp b/deps/oblib/unittest/lib/trace/test_trace.cpp index 8428fc3b0..67c79e245 100644 --- a/deps/oblib/unittest/lib/trace/test_trace.cpp +++ b/deps/oblib/unittest/lib/trace/test_trace.cpp @@ -54,7 +54,7 @@ TEST(TestTrace, basic_test) FLUSH_TRACE(); auto t = std::thread([=]() { // RPC框架端完成初始化 - OBTRACE->init(trace_id, proxy->span_id_, (auto_flush << 7) + level); + OBTRACE->init(trace_id, proxy->get_span_id(), (auto_flush << 7) + level); // FLTSpanGuard(ObSql); FLT_SET_TAG(sql_id, 123);