SpringCloud 創(chuàng)建新的跨度

2023-12-01 16:10 更新

如果您不想手動(dòng)創(chuàng)建本地spans,則可以使用@NewSpan批注。另外,我們提供了@SpanTag批注以自動(dòng)方式添加標(biāo)簽。

現(xiàn)在我們可以考慮一些用法示例。

@NewSpan
void testMethod();

在不帶任何參數(shù)的情況下對(duì)方法進(jìn)行注釋會(huì)導(dǎo)致創(chuàng)建一個(gè)新的跨度,其名稱(chēng)等于帶注釋的方法名稱(chēng)。

@NewSpan("customNameOnTestMethod4")
void testMethod4();

如果您在批注中提供值(直接或通過(guò)設(shè)置name參數(shù)),則創(chuàng)建的跨度將提供的值作為名稱(chēng)。

// method declaration
@NewSpan(name = "customNameOnTestMethod5")
void testMethod5(@SpanTag("testTag") String param);

// and method execution
this.testBean.testMethod5("test");

您可以將名稱(chēng)和標(biāo)簽結(jié)合在一起。讓我們專(zhuān)注于后者。在這種情況下,帶注釋的方法的參數(shù)運(yùn)行時(shí)值的值將成為標(biāo)記的值。在我們的示例中,標(biāo)記鍵為testTag,標(biāo)記值為test。

@NewSpan(name = "customNameOnTestMethod3")
@Override
public void testMethod3() {
}

您可以在類(lèi)和接口上都放置@NewSpan批注。如果您重寫(xiě)接口的方法并為@NewSpan批注提供一個(gè)不同的值,則最具體的將獲勝(在這種情況下,將設(shè)置customNameOnTestMethod3)。

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

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)