Hello!
As per Spring Cloud Sleuth was migrated to Micrometer Tracing, wanted to know how is the property equivalent to
spring.sleuth.web.skipPattern
As a result to configure URIs that I want to skip be posted to Zipkin server.
For example, all actuator/** or swagger requests are being sent to Zipkin and I don't want that:
Do we have any property/configuration that we can do to achieve this?
Thanks in advance.
Comment From: giger85
Hi, @trcoelho
In order to apply NOOP observation for some requests, I created ObservationPredicate type bean.
Here is example kotlin code.
import io.micrometer.observation.Observation.Context
import io.micrometer.observation.ObservationPredicate
import org.springframework.http.server.observation.ServerRequestObservationContext
@Bean
fun noopServerRequestObservationPredicate(): ObservationPredicate {
val noopPathSet = setOf("/actuator")
return ObservationPredicate { _, context ->
if (context !is ServerRequestObservationContext) {
return@ObservationPredicate true
}
val servletRequest = context.carrier
val path = servletRequest.requestURI
noopPathSet.none { path.startsWith(it) }
}
}
It might not equivalent to skip pattern of spring cloud sleuth.
Comment From: wilkinsona
A predicate is the recommended approach. Thanks, @giger85.
@trcoelho, if you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. You may also want to open a Micrometer Tracing issue and suggest an update to the migration guide.
Comment From: sanjayamin
I've spring boot api-gateway project. I tried following ObservationPredicate to exclude /actuaotr/prometheus to skip be posted to Zipkin server but that doesn't work. Any suggestion?
@Configuration
public class TracingConfig {
@Bean
public ObservationPredicate noActuator() {
return (name, context) -> {
if (context instanceof ServerRequestObservationContext srCtx) {
return !srCtx.getPathPattern().contains("/actuator/");
}
return true;
};
}
}
Comment From: scottfrederick
@sanjayamin As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Please use Stack Overflow for questions like this.
Comment From: trcoelho
Hi @sanjayamin, please find below what I've done to have it filtered:
application.properties
springdoc.api-docs.path=/api-docs
springdoc.swagger-ui.path=/swagger-ui
management.endpoints.web.base-path=/actuator
ZipkinConfig.java
package com.example.application;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.server.observation.ServerRequestObservationContext;
import io.micrometer.observation.ObservationPredicate;
import jakarta.servlet.http.HttpServletRequest;
@Configuration
public class ZipkinConfig {
@Value("${springdoc.api-docs.path}")
private String apiDocsPath;
@Value("${springdoc.swagger-ui.path}")
private String swaggerPath;
@Value("${management.endpoints.web.base-path}")
private String actuatorPath;
@Bean
ObservationPredicate noopServerRequestObservationPredicate() {
ObservationPredicate predicate = (name, context) -> {
if(context instanceof ServerRequestObservationContext c) {
HttpServletRequest servletRequest = c.getCarrier();
String requestURI = servletRequest.getRequestURI();
if(StringUtils.containsAny(requestURI, actuatorPath, swaggerPath, apiDocsPath)) {
return false;
}
}
if(StringUtils.equalsAny(name,"spring.security.filterchains","spring.security.authorizations","spring.security.http.secured.requests")) {
return false;
}
return true;
};
return predicate;
}
}
It filters all spring doc apis, swagger path and also actuator. Hope it helps.
Thank you.