-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Add support for the @SpanTag annotation #38662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Looking at #37640, it seems that the application needs to define a custom |
Maybe good to mention. While using Spring Boot 3.1.0 we provided this for the users of our framework with the following autoconfiguration where we did not need to define any /**
* Creates the beans needed to be able to use AOP for the {@link io.micrometer.tracing.annotation.NewSpan},
* {@link io.micrometer.tracing.annotation.ContinueSpan} and {@link io.micrometer.tracing.annotation.SpanTag} annotations
*/
@AutoConfiguration(after = AxleOpenTelemetryTracingAutoConfiguration.class)
@ConditionalOnEnabledTracing
@ConditionalOnProperty(value = AxleTracingProperties.AopProperties.PROP_ENABLED, havingValue = "true", matchIfMissing = true)
public class AxleTracingAopAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public NewSpanParser axleNewSpanParser() {
return new DefaultNewSpanParser();
}
@Bean
@ConditionalOnMissingBean
public MethodInvocationProcessor axleMethodInvocationProcessor(
NewSpanParser newSpanParser,
Tracer tracer,
BeanFactory beanFactory
) {
return new ImperativeMethodInvocationProcessor(
newSpanParser,
tracer,
beanFactory::getBean,
beanFactory::getBean
);
}
@Bean
@ConditionalOnMissingBean
public SpanAspect axleSpanAspect(MethodInvocationProcessor methodInvocationProcessor) {
return new SpanAspect(methodInvocationProcessor);
}
} |
Btw there is also |
In Spring Cloud Sleuth the default was SPel. Micrometer Tracing has no notion of SPel nor Spring so it can't ship this component. That should be coming from Boot I guess? 🤷 |
I have something in this branch. It auto-configures the |
I checked it out and it makes perfect sense @mhalbritter 👍 |
We decided to ship that as an enhancement in 3.3. If you want to have it for 3.2 already, please see the code in my branch. It's not that much: @Bean
@ConditionalOnMissingBean
SpanTagAnnotationHandler spanTagAnnotationHandler(BeanFactory beanFactory) {
ValueExpressionResolver valueExpressionResolver = new SpelTagValueExpressionResolver();
return new SpanTagAnnotationHandler(beanFactory::getBean, (ignored) -> valueExpressionResolver);
} private static class SpelTagValueExpressionResolver implements ValueExpressionResolver {
@Override
public String resolve(String expression, Object parameter) {
try {
SimpleEvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();
ExpressionParser expressionParser = new SpelExpressionParser();
Expression expressionToEvaluate = expressionParser.parseExpression(expression);
return expressionToEvaluate.getValue(context, parameter, String.class);
} catch (Exception ex) {
throw new IllegalStateException("Unable to evaluate SpEL expression '%s'".formatted(expression), ex);
}
}
} |
Spring Boot 3.2.0 came with a number of Observability improvements, supporting a number of Micrometer annotations.
@SpanTag is not mentioned here, and according to our tests, also not working out of the box. Is this done by design or would this be a bug?
To make things easier, I've made a demo project with a unit test that reproduces the issue. You can do so by opening the project and running the
AopTracingTest
or running./mvnw clean verify
. Next to the@SpanTag
annotation it also verifies the working of other tracing annotations, which currently do work.The text was updated successfully, but these errors were encountered: