fix wrong span_id in full link tracing
This commit is contained in:
		
							
								
								
									
										1
									
								
								deps/oblib/src/lib/trace/ob_trace.cpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								deps/oblib/src/lib/trace/ob_trace.cpp
									
									
									
									
										vendored
									
									
								
							@ -413,6 +413,7 @@ ObSpanCtx* ObTrace::begin_span(uint32_t span_type, uint8_t level, bool is_follow
 | 
				
			|||||||
      new_span = freed_span_.remove_last();
 | 
					      new_span = freed_span_.remove_last();
 | 
				
			||||||
      current_span_.add_first(new_span);
 | 
					      current_span_.add_first(new_span);
 | 
				
			||||||
      new_span->span_type_ = span_type;
 | 
					      new_span->span_type_ = span_type;
 | 
				
			||||||
 | 
					      new_span->span_id_.high_ = 0;
 | 
				
			||||||
      new_span->span_id_.low_ = ++seq_;
 | 
					      new_span->span_id_.low_ = ++seq_;
 | 
				
			||||||
      new_span->span_id_.high_ = 0;
 | 
					      new_span->span_id_.high_ = 0;
 | 
				
			||||||
      new_span->source_span_ = last_active_span_;
 | 
					      new_span->source_span_ = last_active_span_;
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										14
									
								
								deps/oblib/src/lib/trace/ob_trace.h
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										14
									
								
								deps/oblib/src/lib/trace/ob_trace.h
									
									
									
									
										vendored
									
									
								
							@ -28,7 +28,7 @@
 | 
				
			|||||||
#define FLT_END_SPAN(span)                                      \
 | 
					#define FLT_END_SPAN(span)                                      \
 | 
				
			||||||
if (OB_NOT_NULL(span)) {                                        \
 | 
					if (OB_NOT_NULL(span)) {                                        \
 | 
				
			||||||
  OBTRACE->end_span(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();                                              \
 | 
					    FLUSH_TRACE();                                              \
 | 
				
			||||||
  }                                                             \
 | 
					  }                                                             \
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -126,6 +126,7 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
struct ObTagCtxBase
 | 
					struct ObTagCtxBase
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					  friend void flush_trace();
 | 
				
			||||||
  ObTagCtxBase() : next_(nullptr), tag_type_(0) {}
 | 
					  ObTagCtxBase() : next_(nullptr), tag_type_(0) {}
 | 
				
			||||||
  virtual ~ObTagCtxBase() {}
 | 
					  virtual ~ObTagCtxBase() {}
 | 
				
			||||||
  virtual int tostring(char* buf, const int64_t buf_len, int64_t& pos)
 | 
					  virtual int tostring(char* buf, const int64_t buf_len, int64_t& pos)
 | 
				
			||||||
@ -146,6 +147,7 @@ struct ObTagCtxBase
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					protected:
 | 
				
			||||||
  ObTagCtxBase* next_;
 | 
					  ObTagCtxBase* next_;
 | 
				
			||||||
  uint16_t tag_type_;
 | 
					  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 <typename T>
 | 
					template <typename T>
 | 
				
			||||||
struct ObTagCtx final : public ObTagCtxBase
 | 
					struct ObTagCtx final : public ObTagCtxBase
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					  friend struct ObTrace;
 | 
				
			||||||
  ObTagCtx() {}
 | 
					  ObTagCtx() {}
 | 
				
			||||||
  virtual ~ObTagCtx() override {}
 | 
					  virtual ~ObTagCtx() override {}
 | 
				
			||||||
  virtual int tostring(char* buf, const int64_t buf_len, int64_t& pos) 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;
 | 
					    return ret;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
  T data_;
 | 
					  T data_;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct ObSpanCtx final : public common::ObDLinkBase<ObSpanCtx>
 | 
					struct ObSpanCtx final : public common::ObDLinkBase<ObSpanCtx>
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					  friend struct ObTrace;
 | 
				
			||||||
 | 
					  friend void flush_trace();
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
  ObSpanCtx();
 | 
					  ObSpanCtx();
 | 
				
			||||||
 | 
					  OB_INLINE bool is_inited() const { return span_id_.is_inited(); }
 | 
				
			||||||
 | 
					  UUID get_span_id() const { return span_id_; }
 | 
				
			||||||
  UUID span_id_;
 | 
					  UUID span_id_;
 | 
				
			||||||
  ObSpanCtx* source_span_;
 | 
					  ObSpanCtx* source_span_;
 | 
				
			||||||
  int64_t start_ts_;
 | 
					  int64_t start_ts_;
 | 
				
			||||||
@ -348,7 +356,7 @@ public:
 | 
				
			|||||||
  {
 | 
					  {
 | 
				
			||||||
    span_ = OBTRACE->begin_span(span_type, level, false);
 | 
					    span_ = OBTRACE->begin_span(span_type, level, false);
 | 
				
			||||||
#ifndef NDEBUG
 | 
					#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());
 | 
					      FLT_SET_TAG(span_back_trace, lbt());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								deps/oblib/unittest/lib/trace/test_trace.cpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								deps/oblib/unittest/lib/trace/test_trace.cpp
									
									
									
									
										vendored
									
									
								
							@ -54,7 +54,7 @@ TEST(TestTrace, basic_test)
 | 
				
			|||||||
  FLUSH_TRACE();
 | 
					  FLUSH_TRACE();
 | 
				
			||||||
  auto t = std::thread([=]() {
 | 
					  auto t = std::thread([=]() {
 | 
				
			||||||
    // RPC框架端完成初始化
 | 
					    // 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);
 | 
					    FLTSpanGuard(ObSql);
 | 
				
			||||||
    FLT_SET_TAG(sql_id, 123);
 | 
					    FLT_SET_TAG(sql_id, 123);
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user