SpringCloud 創(chuàng)建并完成spans

2023-12-01 16:00 更新

您可以使用Tracer手動創(chuàng)建spans,如以下示例所示:

// Start a span. If there was a span present in this thread it will become
// the `newSpan`'s parent.
Span newSpan = this.tracer.nextSpan().name("calculateTax");
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(newSpan.start())) {
	// ...
	// You can tag a span
	newSpan.tag("taxValue", taxValue);
	// ...
	// You can log an event on a span
	newSpan.annotate("taxCalculated");
}
finally {
	// Once done remember to finish the span. This will allow collecting
	// the span to send it to Zipkin
	newSpan.finish();
}

在前面的示例中,我們可以看到如何創(chuàng)建跨度的新實例。如果此線程中已經(jīng)有一個跨度,它將成為新跨度的父級。

創(chuàng)建跨度后,請始終保持清潔。另外,請務(wù)必完成要發(fā)送到Zipkin的所有跨度。

如果您的跨度包含的名稱大于50個字符,則該名稱將被截斷為50個字符。您的名字必須明確明確。知名人士會導(dǎo)致延遲問題,有時甚至?xí)l(fā)例外情況。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號