Skip to content

Commit

Permalink
feat: ignore tracing for specific routes
Browse files Browse the repository at this point in the history
  • Loading branch information
CChuYong committed Jul 14, 2024
1 parent a9475b2 commit 8a90e07
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
30 changes: 30 additions & 0 deletions api-gateway/src/main/java/kr/mafoo/gateway/TracingConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package kr.mafoo.gateway;

import io.micrometer.observation.ObservationPredicate;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.observation.ServerRequestObservationContext;

@Configuration
public class TracingConfig {
@Bean
ObservationPredicate noopServerRequestObservationPredicate() {
ObservationPredicate predicate = (name, context) -> {
if(context instanceof ServerRequestObservationContext c) {
ServerHttpRequest servletRequest = c.getCarrier();
String requestURI = servletRequest.getPath().toString();
if(StringUtils.containsAny(requestURI, "actuator", "swagger", "api-docs")) {
return false;
}
}
if (StringUtils.equalsAny(name,"spring.security.filterchains","spring.security.authorizations","spring.security.http.secured.requests")) {
return false;
}
return true;
};

return predicate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package kr.mafoo.photo.config;

import io.micrometer.observation.ObservationPredicate;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.observation.ServerRequestObservationContext;

@Configuration
public class TracingConfig {
@Bean
ObservationPredicate noopServerRequestObservationPredicate() {
ObservationPredicate predicate = (name, context) -> {
if(context instanceof ServerRequestObservationContext c) {
ServerHttpRequest servletRequest = c.getCarrier();
String requestURI = servletRequest.getPath().toString();
if(StringUtils.containsAny(requestURI, "actuator", "swagger", "api-docs")) {
return false;
}
}
if (StringUtils.equalsAny(name,"spring.security.filterchains","spring.security.authorizations","spring.security.http.secured.requests")) {
return false;
}
return true;
};

return predicate;
}
}
30 changes: 30 additions & 0 deletions user-service/src/main/java/kr/mafoo/user/config/TracingConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package kr.mafoo.user.config;

import io.micrometer.observation.ObservationPredicate;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.observation.ServerRequestObservationContext;

@Configuration
public class TracingConfig {
@Bean
ObservationPredicate noopServerRequestObservationPredicate() {
ObservationPredicate predicate = (name, context) -> {
if(context instanceof ServerRequestObservationContext c) {
ServerHttpRequest servletRequest = c.getCarrier();
String requestURI = servletRequest.getPath().toString();
if(StringUtils.containsAny(requestURI, "actuator", "swagger", "api-docs")) {
return false;
}
}
if (StringUtils.equalsAny(name,"spring.security.filterchains","spring.security.authorizations","spring.security.http.secured.requests")) {
return false;
}
return true;
};

return predicate;
}
}

0 comments on commit 8a90e07

Please sign in to comment.