1
0
mirror of synced 2026-05-22 21:33:16 +00:00

Polish Span and Meter Names

Closes gh-12156
This commit is contained in:
Josh Cummings
2022-11-16 13:52:06 -07:00
parent 88e64bac0c
commit e08ed89403
7 changed files with 94 additions and 94 deletions
@@ -37,11 +37,10 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.log.LogMessage;
import org.springframework.security.web.util.UrlUtils;
/**
* A {@link org.springframework.security.web.server.FilterChainProxy.FilterChainDecorator}
* that wraps the chain in before and after observations
* A {@link org.springframework.security.web.FilterChainProxy.FilterChainDecorator} that
* wraps the chain in before and after observations
*
* @author Josh Cummings
* @since 6.0
@@ -75,14 +74,16 @@ public final class ObservationFilterChainDecorator implements FilterChainProxy.F
private FilterChain wrapSecured(FilterChain original) {
return (req, res) -> {
AroundFilterObservation parent = observation((HttpServletRequest) req);
Observation observation = Observation.createNotStarted(SECURED_OBSERVATION_NAME, this.registry);
Observation observation = Observation.createNotStarted(SECURED_OBSERVATION_NAME, this.registry)
.contextualName("secured request");
parent.wrap(FilterObservation.create(observation).wrap(original)).doFilter(req, res);
};
}
private FilterChain wrapUnsecured(FilterChain original) {
return (req, res) -> {
Observation observation = Observation.createNotStarted(UNSECURED_OBSERVATION_NAME, this.registry);
Observation observation = Observation.createNotStarted(UNSECURED_OBSERVATION_NAME, this.registry)
.contextualName("unsecured request");
FilterObservation.create(observation).wrap(original).doFilter(req, res);
};
}
@@ -189,8 +190,8 @@ public final class ObservationFilterChainDecorator implements FilterChainProxy.F
}
private AroundFilterObservation parent(HttpServletRequest request) {
FilterChainObservationContext beforeContext = FilterChainObservationContext.before(request);
FilterChainObservationContext afterContext = FilterChainObservationContext.after(request);
FilterChainObservationContext beforeContext = FilterChainObservationContext.before();
FilterChainObservationContext afterContext = FilterChainObservationContext.after();
Observation before = Observation.createNotStarted(this.convention, () -> beforeContext, this.registry);
Observation after = Observation.createNotStarted(this.convention, () -> afterContext, this.registry);
AroundFilterObservation parent = AroundFilterObservation.create(before, after);
@@ -409,8 +410,6 @@ public final class ObservationFilterChainDecorator implements FilterChainProxy.F
static final class FilterChainObservationContext extends Observation.Context {
private final ServletRequest request;
private final String filterSection;
private String filterName;
@@ -419,29 +418,17 @@ public final class ObservationFilterChainDecorator implements FilterChainProxy.F
private int chainSize;
private FilterChainObservationContext(ServletRequest request, String filterSection) {
private FilterChainObservationContext(String filterSection) {
this.filterSection = filterSection;
this.request = request;
setContextualName("security filterchain " + filterSection);
}
static FilterChainObservationContext before(ServletRequest request) {
return new FilterChainObservationContext(request, "before");
static FilterChainObservationContext before() {
return new FilterChainObservationContext("before");
}
static FilterChainObservationContext after(ServletRequest request) {
return new FilterChainObservationContext(request, "after");
}
@Override
public void setName(String name) {
super.setName(name);
if (name != null) {
setContextualName(name + "." + this.filterSection);
}
}
String getRequestLine() {
return requestLine((HttpServletRequest) this.request);
static FilterChainObservationContext after() {
return new FilterChainObservationContext("after");
}
String getFilterSection() {
@@ -472,32 +459,31 @@ public final class ObservationFilterChainDecorator implements FilterChainProxy.F
this.chainSize = chainSize;
}
private static String requestLine(HttpServletRequest request) {
return request.getMethod() + " " + UrlUtils.buildRequestUrl(request);
}
}
static final class FilterChainObservationConvention
implements ObservationConvention<FilterChainObservationContext> {
static final String CHAIN_OBSERVATION_NAME = "spring.security.http.chains";
static final String CHAIN_OBSERVATION_NAME = "spring.security.filterchains";
private static final String REQUEST_LINE_NAME = "request.line";
private static final String CHAIN_POSITION_NAME = "spring.security.filterchain.position";
private static final String CHAIN_POSITION_NAME = "chain.position";
private static final String CHAIN_SIZE_NAME = "spring.security.filterchain.size";
private static final String CHAIN_SIZE_NAME = "chain.size";
private static final String FILTER_SECTION_NAME = "security.security.reached.filter.section";
private static final String FILTER_SECTION_NAME = "filter.section";
private static final String FILTER_NAME = "current.filter.name";
private static final String FILTER_NAME = "spring.security.reached.filter.name";
@Override
public String getName() {
return CHAIN_OBSERVATION_NAME;
}
@Override
public String getContextualName(FilterChainObservationContext context) {
return "security filterchain " + context.getFilterSection();
}
@Override
public KeyValues getLowCardinalityKeyValues(FilterChainObservationContext context) {
KeyValues kv = KeyValues.of(CHAIN_SIZE_NAME, String.valueOf(context.getChainSize()))
@@ -509,12 +495,6 @@ public final class ObservationFilterChainDecorator implements FilterChainProxy.F
return kv;
}
@Override
public KeyValues getHighCardinalityKeyValues(FilterChainObservationContext context) {
String requestLine = context.getRequestLine();
return KeyValues.of(REQUEST_LINE_NAME, requestLine);
}
@Override
public boolean supportsContext(Observation.Context context) {
return context instanceof FilterChainObservationContext;
@@ -75,14 +75,16 @@ public final class ObservationWebFilterChainDecorator implements WebFilterChainP
private WebFilterChain wrapSecured(WebFilterChain original) {
return (exchange) -> {
AroundWebFilterObservation parent = observation(exchange);
Observation observation = Observation.createNotStarted(SECURED_OBSERVATION_NAME, this.registry);
Observation observation = Observation.createNotStarted(SECURED_OBSERVATION_NAME, this.registry)
.contextualName("secured request");
return parent.wrap(WebFilterObservation.create(observation).wrap(original)).filter(exchange);
};
}
private WebFilterChain wrapUnsecured(WebFilterChain original) {
return (exchange) -> {
Observation observation = Observation.createNotStarted(UNSECURED_OBSERVATION_NAME, this.registry);
Observation observation = Observation.createNotStarted(UNSECURED_OBSERVATION_NAME, this.registry)
.contextualName("unsecured request");
return WebFilterObservation.create(observation).wrap(original).filter(exchange);
};
}
@@ -210,8 +212,8 @@ public final class ObservationWebFilterChainDecorator implements WebFilterChainP
}
private AroundWebFilterObservation parent(ServerWebExchange exchange) {
WebFilterChainObservationContext beforeContext = WebFilterChainObservationContext.before(exchange);
WebFilterChainObservationContext afterContext = WebFilterChainObservationContext.after(exchange);
WebFilterChainObservationContext beforeContext = WebFilterChainObservationContext.before();
WebFilterChainObservationContext afterContext = WebFilterChainObservationContext.after();
Observation before = Observation.createNotStarted(this.convention, () -> beforeContext, this.registry);
Observation after = Observation.createNotStarted(this.convention, () -> afterContext, this.registry);
AroundWebFilterObservation parent = AroundWebFilterObservation.create(before, after);
@@ -419,8 +421,6 @@ public final class ObservationWebFilterChainDecorator implements WebFilterChainP
static final class WebFilterChainObservationContext extends Observation.Context {
private final ServerWebExchange exchange;
private final String filterSection;
private String filterName;
@@ -429,29 +429,16 @@ public final class ObservationWebFilterChainDecorator implements WebFilterChainP
private int chainSize;
private WebFilterChainObservationContext(ServerWebExchange exchange, String filterSection) {
this.exchange = exchange;
private WebFilterChainObservationContext(String filterSection) {
this.filterSection = filterSection;
}
static WebFilterChainObservationContext before(ServerWebExchange exchange) {
return new WebFilterChainObservationContext(exchange, "before");
static WebFilterChainObservationContext before() {
return new WebFilterChainObservationContext("before");
}
static WebFilterChainObservationContext after(ServerWebExchange exchange) {
return new WebFilterChainObservationContext(exchange, "after");
}
@Override
public void setName(String name) {
super.setName(name);
if (name != null) {
setContextualName(name + "." + this.filterSection);
}
}
String getRequestLine() {
return this.exchange.getRequest().getPath().toString();
static WebFilterChainObservationContext after() {
return new WebFilterChainObservationContext("after");
}
String getFilterSection() {
@@ -487,23 +474,26 @@ public final class ObservationWebFilterChainDecorator implements WebFilterChainP
static final class WebFilterChainObservationConvention
implements ObservationConvention<WebFilterChainObservationContext> {
static final String CHAIN_OBSERVATION_NAME = "spring.security.http.chains";
static final String CHAIN_OBSERVATION_NAME = "spring.security.filterchains";
private static final String REQUEST_LINE_NAME = "request.line";
private static final String CHAIN_POSITION_NAME = "spring.security.filterchain.position";
private static final String CHAIN_POSITION_NAME = "chain.position";
private static final String CHAIN_SIZE_NAME = "spring.security.filterchain.size";
private static final String CHAIN_SIZE_NAME = "chain.size";
private static final String FILTER_SECTION_NAME = "spring.security.reached.filter.section";
private static final String FILTER_SECTION_NAME = "filter.section";
private static final String FILTER_NAME = "current.filter.name";
private static final String FILTER_NAME = "spring.security.reached.filter.name";
@Override
public String getName() {
return CHAIN_OBSERVATION_NAME;
}
@Override
public String getContextualName(WebFilterChainObservationContext context) {
return "security filterchain " + context.getFilterSection();
}
@Override
public KeyValues getLowCardinalityKeyValues(WebFilterChainObservationContext context) {
KeyValues kv = KeyValues.of(CHAIN_SIZE_NAME, String.valueOf(context.getChainSize()))
@@ -515,12 +505,6 @@ public final class ObservationWebFilterChainDecorator implements WebFilterChainP
return kv;
}
@Override
public KeyValues getHighCardinalityKeyValues(WebFilterChainObservationContext context) {
String requestLine = context.getRequestLine();
return KeyValues.of(REQUEST_LINE_NAME, requestLine);
}
@Override
public boolean supportsContext(Observation.Context context) {
return context instanceof WebFilterChainObservationContext;