SpringCloud 連續(xù)跨度

2023-12-01 16:01 更新

有時,您不想創(chuàng)建一個新跨度,但想繼續(xù)一個跨度。這種情況的示例如下:

  • AOP:如果在到達方面之前已經(jīng)創(chuàng)建了一個跨度,則您可能不想創(chuàng)建一個新的跨度。
  • Hystrix:執(zhí)行Hystrix命令很可能是當前處理的邏輯部分。實際上,它僅僅是技術(shù)實現(xiàn)細節(jié),您不一定要在跟蹤中將其反映為一個單獨的實體。

要繼續(xù)跨度,可以使用brave.Tracer,如以下示例所示:

// let's assume that we're in a thread Y and we've received
// the `initialSpan` from thread X
Span continuedSpan = this.tracer.toSpan(newSpan.context());
try {
	// ...
	// You can tag a span
	continuedSpan.tag("taxValue", taxValue);
	// ...
	// You can log an event on a span
	continuedSpan.annotate("taxCalculated");
}
finally {
	// Once done remember to flush the span. That means that
	// it will get reported but the span itself is not yet finished
	continuedSpan.flush();
}
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號