You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are having reactive context, so followed lates PR to accommodate the solution as we are still using spring-boot 3.0.6.
Implemented:
public class TelemetryFilterConfig implements WebFilter, Ordered {
private final ServerWebExchangeAttributesGetter serverWebExchangeAttributesGetter;
private final Instrumenter<ServerWebExchange, ServerWebExchange> instrumenter;
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
Context parentContext = Context.current();
Mono<Void> source = chain.filter(exchange);
return new TelemetryMonoWrapper(source, instrumenter, serverWebExchangeAttributesGetter, parentContext, exchange);
}
@Override
public int getOrder() {
// return Ordered.HIGHEST_PRECEDENCE + 1;
return -1;
}
}
also to mentioned that having Ordered.HIGHEST_PRECEDENCE + 1 will actually get blocked in: !instrumenter.shouldStart(parentContext, exchange)
After this filter, in the chain is decorator filter, having main purpose of logging request/response:
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
if (!passToLog(exchange)) {
return chain.filter(exchange);
}
BodyCaptureExchange bodyCaptureExchange = new BodyCaptureExchange(exchange, obfuscateHeaders, UUID.randomUUID());
return bodyCaptureExchange.getRequest().getFullBody()
.doOnSuccess(requestBodyLog -> log.info("Request: {}", requestBodyLog))
.flatMap(unused -> chain.filter(bodyCaptureExchange))
.doOnSuccess(unused -> log.info("Response: {}", bodyCaptureExchange.getResponse().getFullBody()));
}
private boolean passToLog(ServerWebExchange exchange) {
String path = Optional.ofNullable(exchange)
.map(ServerWebExchange::getRequest)
.map(ServerHttpRequest::getPath)
.map(PathContainer::value)
.orElse("");
for (String value : exclude) {
if (!path.isBlank() && path.startsWith(value)) {
return false;
}
}
return true;
}
@Override
public int getOrder() {
return 1;
}
at any given time, after:
@Override
public void subscribe(CoreSubscriber<? super Void> actual) {
if (!instrumenter.shouldStart(parentContext, exchange)) {
source.subscribe(actual);
return;
}
Context currentContext = instrumenter.start(parentContext, exchange);
try (Scope ignored = currentContext.makeCurrent()) {
this.source.subscribe(
new TelemetryWrappedSubscriber(actual, currentContext, instrumenter, serverWebExchangeAttributesGetter, exchange));
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We are having reactive context, so followed lates PR to accommodate the solution as we are still using spring-boot 3.0.6.
Implemented:
also to mentioned that having
Ordered.HIGHEST_PRECEDENCE + 1
will actually get blocked in:!instrumenter.shouldStart(parentContext, exchange)
After this filter, in the chain is decorator filter, having main purpose of logging request/response:
at any given time, after:
starting on subscribe new context, calling
Context.current()
is always nullTrying to apply and customise this solution: https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/7899/files#diff-75440060d9275950a4421e5518996d91f2055c75ff35fb105194ccec6cf644a6
Configuration looks like:
Beta Was this translation helpful? Give feedback.
All reactions