Skip to content

Commit 33594ec

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

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
* wraps the chain in before and after observations
4747
*
4848
* @author Josh Cummings
49+
* @author Nikita Konev
4950
* @since 6.0
5051
*/
5152
public final class ObservationFilterChainDecorator implements FilterChainProxy.FilterChainDecorator {
@@ -250,6 +251,16 @@ private void wrapFilter(ServletRequest request, ServletResponse response, Filter
250251
private AroundFilterObservation parent(HttpServletRequest request) {
251252
FilterChainObservationContext beforeContext = FilterChainObservationContext.before();
252253
FilterChainObservationContext afterContext = FilterChainObservationContext.after();
254+
255+
AroundFilterObservation existingParentObservation = (AroundFilterObservation) request
256+
.getAttribute(ATTRIBUTE);
257+
if (existingParentObservation != null) {
258+
beforeContext
259+
.setParentObservation(existingParentObservation.before().getContext().getParentObservation());
260+
afterContext
261+
.setParentObservation(existingParentObservation.after().getContext().getParentObservation());
262+
}
263+
253264
Observation before = Observation.createNotStarted(this.convention, () -> beforeContext, this.registry);
254265
Observation after = Observation.createNotStarted(this.convention, () -> afterContext, this.registry);
255266
AroundFilterObservation parent = AroundFilterObservation.create(before, after);

0 commit comments

Comments
 (0)