spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.52k stars 3.32k forks source link

How to get the "Mapping Route id" (and more) from within a custom filter #2515

Closed MonDeveloper closed 2 years ago

MonDeveloper commented 2 years ago

In order to have a more contextualized log, I'm wondering if there a way to access to some mapping route contextual information from within the Custom Filters and Custom Predicates.

A practical example is to log the Mapping Route Id together with other info I'm logging from my Custom Filters and/or Predicates.

Id could be very helpful showing why that specific request has been treated (matched / not matched / modified)

Thanks in advance, mM

YunWZ commented 2 years ago

Like this: exchange.getRequiredAttribute(org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_PREDICATE_ROUTE_ATTR). or: exchange.getAttributes().get(org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_PREDICATE_ROUTE_ATTR)

spring-cloud-issues commented 2 years ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-cloud-issues commented 2 years ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.