Skip to content

Fix traceId discrepancy in case error in servlet web #17134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 6.4.x
Choose a base branch
from

Conversation

nkonev
Copy link
Contributor

@nkonev nkonev commented May 18, 2025

Fixes #12610


As I see from my research, the bug happens only in the real servlet environment, supposedly because of HttpServletResponse.sendError(), I didn't manage to reproduce it via mockMvc.
Tomcat creates a new HttpServletRequest in case error, which is related to "/error" path, which will be served by ErrorController.
Fortunately, request attributes are copied from the original request to the "/error"-related one, so we can put the ObservationView into the original request in order to extract this ObservationView from "/error"-related request and create a new parent observation with a given parent ObservationView. The last ObservationView propagates TraceContext to the new Observation so we have the same traceId.


Reproducer is here https://github.com/nkonev/trace-discrepancy-reproducer

curl -i 'http://localhost:8060/internal/profile/auth' -X GET -H 'Accept: text/plain, */*'

To check that the bug is fixed, you can run publishMavenJavaPublicationToMavenLocal in spring-security:web
image

then switch to the SNAPSHOT dependency nkonev/trace-discrepancy-reproducer@131a271

Before:
Screenshot From 2025-05-21 17-45-08
Screenshot From 2025-05-21 17-45-31

After:
Screenshot From 2025-05-21 17-54-26
Screenshot From 2025-05-21 17-54-45

Signed-off-by: Nikita Konev <nikit.cpp@yandex.ru>
@nkonev
Copy link
Contributor Author

nkonev commented May 18, 2025

PTAL @jzheaux

nkonev added a commit to nkonev/videochat that referenced this pull request May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants