Skip to content

Write TraceId in HTTP Response headers #40857

New issue

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

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

Already on GitHub? # to your account

Closed
bclozel opened this issue May 21, 2024 · 6 comments
Closed

Write TraceId in HTTP Response headers #40857

bclozel opened this issue May 21, 2024 · 6 comments
Assignees
Labels
theme: observability Issues related to observability type: enhancement A general enhancement
Milestone

Comments

@bclozel
Copy link
Member

bclozel commented May 21, 2024

As of spring-projects/spring-framework#30632, Spring Framework allows to extend the ServerHttpObservationFilter. Spring Boot could extend this class and contribute it if "micrometer-tracing" is on the classpath and a Tracer bean is available.

The sample implementation is quite straightforward. We should then adapt the auto-configuration to only contribute this filter subclass if conditions are meant, otherwise keep contributing the current setup.

@bclozel bclozel added type: enhancement A general enhancement theme: observability Issues related to observability labels May 21, 2024
@bclozel bclozel added this to the 3.4.x milestone May 21, 2024
@bclozel bclozel self-assigned this May 21, 2024
@neiser
Copy link
Contributor

neiser commented May 23, 2024

@bclozel Thanks for pushing this forward. Adding a TraceId Response Header is something I usually configure by hand and it would be nice if that was something provided by Spring Boot out-of-the-box! Just a bit more Spring Boot magic, which is great IMHO. I can't promise much, but would you accept a Pull Request for this issue?

@bclozel
Copy link
Member Author

bclozel commented May 23, 2024

@neiser thanks for the offer - Spring Boot 3.4 is due next November and the main branch is not currently building against Spring Framework 6.2 so I don't think we're in a position to work on this right now.

@philwebb philwebb modified the milestones: 3.4.x, 3.5.x Jun 17, 2024
@kesrishubham2510
Copy link

kesrishubham2510 commented Sep 22, 2024

Hi @bclozel, I'm new to open source and would like to contribute. This can be learning opportunity for me. In one of my learning project (spring-webflux), I used a WebFilter to add the traceId and spanId to my incoming requests.

Please let me know if I can contribute in any way.

@bclozel bclozel modified the milestones: 3.5.x, 3.5.0-M2 Feb 10, 2025
@dalbani
Copy link
Contributor

dalbani commented Feb 22, 2025

FYI, the wish to have such an X-Trace-Id header was also expressed by users of the OpenTelemetry Java agent: open-telemetry/opentelemetry-java-instrumentation#8175.

I'm curious though why a custom header was chosen, instead of (not yet officially ratified) traceresponse header:

Actually, falling into the rabbit hole of traceresponse, I just discovered that there is a suggestion to (also) use the existing Server-Timing header:

@ciscoo
Copy link

ciscoo commented Feb 22, 2025

X- prefix is deprecated by RFC 6648 as well, but I don't think much attention is given to it.

@bclozel
Copy link
Member Author

bclozel commented Feb 22, 2025

@dalbani nobody requested this format before you did. It's probably a good idea to revisit the header format in the milestone phase. Please create a new issue to request this change.

bclozel added a commit to bclozel/spring-boot that referenced this issue Feb 27, 2025
Prior to this commit, we added support for the "X-Trace-Id" HTTP
response header in spring-projectsgh-40857. This wrote the traceId information for MVC
applications, if the `management.observations.http.server.requests.write-trace-header`
was set.

After receiving feedback from the community, we are revisiting this
feature with the following changes:

* the header is now "traceresponse" and implements the W3C draft
  standard, see https://w3c.github.io/trace-context/#trace-context-http-response-headers-format
* the property is now
  "management.observations.http.server.requests.write-traceresponse"
* both MVC and WebFlux are now supported

Closes spring-projectsgh-44431
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
theme: observability Issues related to observability type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

6 participants