W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
您可能要開始一個新的跨度并提供該跨度的顯式父項。假定范圍的父級在一個線程中,而您想在另一個線程中開始一個新的范圍。在Brave中,每當您調(diào)用nextSpan()
時,它都會參照當前范圍的跨度創(chuàng)建一個跨度。您可以將范圍放入范圍中,然后調(diào)用nextSpan()
,如以下示例所示:
// let's assume that we're in a thread Y and we've received // the `initialSpan` from thread X. `initialSpan` will be the parent // of the `newSpan` Span newSpan = null; try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(initialSpan)) { newSpan = this.tracer.nextSpan().name("calculateCommission"); // ... // You can tag a span newSpan.tag("commissionValue", commissionValue); // ... // You can log an event on a span newSpan.annotate("commissionCalculated"); } finally { // Once done remember to finish the span. This will allow collecting // the span to send it to Zipkin. The tags and events set on the // newSpan will not be present on the parent if (newSpan != null) { newSpan.finish(); } }
創(chuàng)建這樣的跨度后,必須完成它。否則,不會報告該錯誤(例如,報告到Zipkin)。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: