spring-cloud-gateway: Tracing not working with Spring cloud Gateway - springCloudVersion 2023.0.0
Description
I generated sample project from spring initializer (SB 3.2.0 and springCloudVersion 2023.0.0) with io.micrometer:micrometer-tracing-bridge-brave
I created one test route as following:
spring:
cloud:
gateway:
routes:
- id: service_route
uri: http://localhost:8081
predicates:
- Path=/service/**
filters:
- RewritePath=/service(?<segment>/?.*), $\{segment}
I wrote one interceptor as following:
@Configuration
@Slf4j
public class CustomGatewayInterceptor {
@Bean
public GlobalFilter customFilter() {
return new CustomGlobalFilter();
}
public class CustomGlobalFilter implements GlobalFilter, Ordered {
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
log.info("custom global filter");
return chain.filter(exchange);
}
@Override
public int getOrder() {
return 1;
}
}
}
invoked the random endpoint with service in the URL context path
curl http://localhost:8080/service/hello
Problem log is getting printed on console. but it doesn’t have any trace or span Id
2023-12-13T17:40:42.586+05:30 INFO 25644 --- [ctor-http-nio-2] [ ] c.e.demo.rest.CustomGatewayInterceptor : custom global filter
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 16 (2 by maintainers)
Commits related to this issue
- Add spring.reactor.context-propagation=AUTO property to be able to see the Traces on logs. — committed to luisEnriqueSM/msvc-gateway-server by luisEnriqueSM 2 years ago
Could you please try to set
spring.reactor.context-propagation=AUTOif you use Boot 3.2 or newer or callHooks.enableAutomaticContextPropagation()from the first line of yourmainmethod?That’s correct, all is working, Thanks
That’s correct, all is working, Thanks
You need to call
Hooks.enableAutomaticContextPropagation()from anywhere in your app e.g. main()