你可以使用各种注解来管理 span。 有很多很好的理由来管理带有注解的 span,包括:
如果不想手动创建本地 span,可以使用 现在我们可以考虑一些用法示例。 @NewSpan void testMethod(); 在没有任何参数的情况下注解该方法会导致创建一个新的 span,其名称等于注解的方法名称。 @NewSpan("customNameOnTestMethod4") void testMethod4();
如果在注解中提供值(直接或通过设置 // method declaration @NewSpan(name = "customNameOnTestMethod5") void testMethod5(@SpanTag("testTag") String param); // and method execution this.testBean.testMethod5("test");
你可以将名称和标记组合在一起。让我们集中讨论后者。在这种情况下,注解方法的参数运行时值的值将成为标记的值。在我们的示例中,标记键是 @NewSpan(name = "customNameOnTestMethod3") @Override public void testMethod3() { }
你可以在类和接口上放置
如果要将标记和注解添加到现有 span,可以使用 // method declaration @ContinueSpan(log = "testMethod11") void testMethod11(@SpanTag("testTag11") String param); // method execution this.testBean.testMethod11("test"); this.testBean.testMethod13();
(请注意,与 这样,span 就可以继续,并且:
有三种不同的方法可以将标记添加到 span 中。所有这些都由
以下方法的标记值由 考虑以下带注解的方法: @NewSpan public void getAnnotationForTagValueResolver( @SpanTag(key = "test", resolver = TagValueResolver.class) String test) { }
现在进一步考虑以下 @Bean(name = "myCustomTagValueResolver") public TagValueResolver tagValueResolver() { return parameter -> "Value from myCustomTagValueResolver"; }
前面的两个示例导致将标记值设置为 考虑以下带注解的方法: @NewSpan public void getAnnotationForTagValueExpression( @SpanTag(key = "test", expression = "'hello' + ' characters'") String test) { }
|