Skip to content

Commit 5964208

Browse files
committed
Fix traceId discrepancy in case error in servlet web
Signed-off-by: Nikita Konev <[email protected]>
1 parent 16c9794 commit 5964208

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

web/src/main/java/org/springframework/security/web/ObservationFilterChainDecorator.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import io.micrometer.observation.Observation;
3030
import io.micrometer.observation.ObservationConvention;
3131
import io.micrometer.observation.ObservationRegistry;
32+
import io.micrometer.observation.ObservationView;
3233
import jakarta.servlet.Filter;
3334
import jakarta.servlet.FilterChain;
3435
import jakarta.servlet.ServletException;
@@ -46,6 +47,7 @@
4647
* wraps the chain in before and after observations
4748
*
4849
* @author Josh Cummings
50+
* @author Nikita Konev
4951
* @since 6.0
5052
*/
5153
public final class ObservationFilterChainDecorator implements FilterChainProxy.FilterChainDecorator {
@@ -250,6 +252,16 @@ private void wrapFilter(ServletRequest request, ServletResponse response, Filter
250252
private AroundFilterObservation parent(HttpServletRequest request) {
251253
FilterChainObservationContext beforeContext = FilterChainObservationContext.before();
252254
FilterChainObservationContext afterContext = FilterChainObservationContext.after();
255+
256+
AroundFilterObservation existingParentObservation = (AroundFilterObservation) request
257+
.getAttribute(ATTRIBUTE);
258+
if (existingParentObservation != null) {
259+
beforeContext
260+
.setParentObservation(existingParentObservation.before().getContext().getParentObservation());
261+
afterContext
262+
.setParentObservation(existingParentObservation.after().getContext().getParentObservation());
263+
}
264+
253265
Observation before = Observation.createNotStarted(this.convention, () -> beforeContext, this.registry);
254266
Observation after = Observation.createNotStarted(this.convention, () -> afterContext, this.registry);
255267
AroundFilterObservation parent = AroundFilterObservation.create(before, after);

0 commit comments

Comments
 (0)