Skip to content

Change X-Trace-Id response header in favour of "traceresponse" #44431

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
bclozel opened this issue Feb 25, 2025 · 13 comments
Open

Change X-Trace-Id response header in favour of "traceresponse" #44431

bclozel opened this issue Feb 25, 2025 · 13 comments
Assignees
Labels
status: on-hold We can't start working on this issue yet type: enhancement A general enhancement

Comments

@bclozel
Copy link
Member

bclozel commented Feb 25, 2025

We received feedback on our new X-Trace-Id response header support for Spring Boot 3.5 (see #40857). Instead of using an X- header we could be considering one of the currently developed drafts.

It seems both traceresponse and Server-Timing are being considered at the moment, with no clear guidance from the observability community. As far as I understand, Server-Timing has the following priorities:

This specification enables a server to communicate performance metrics about the request-response cycle to the user agent. It also standardizes a JavaScript interface to enable applications to collect, process, and act on these metrics to optimize application delivery.

Browsers can use this header to include its information in their "Developer tools" tabs to give the full picture of the web page performance: from backend activity to resource loading and HTML rendering. The traceId information would only be useful if this UI is also capable of retrieving and rendering the full trace information in the same context.

I think we'll go with the traceresponse header and the related format, as its main goal is to identify a completed request in a tracing system, which better aligns with our intent here.

@bclozel bclozel added the type: enhancement A general enhancement label Feb 25, 2025
@bclozel bclozel added this to the 3.5.0-M3 milestone Feb 25, 2025
@bclozel bclozel self-assigned this Feb 25, 2025
@bclozel bclozel added the status: pending-design-work Needs design work before any code can be developed label Feb 25, 2025
@kzander91
Copy link
Contributor

@bclozel Wouldn't it make sense make the header name configurable? Additionally, is there a reason for not supporting this for WebFlux?

@bclozel
Copy link
Member Author

bclozel commented Feb 26, 2025

Wouldn't it make sense make the header name configurable?

I'm not sure I understand; how would that work?

Additionally, is there a reason for not supporting this for WebFlux?

No, I'm working on it. We were just waiting for community feedback before expanding support.

@kzander91
Copy link
Contributor

kzander91 commented Feb 26, 2025

I'm not sure I understand; how would that work?

Instead of using this constant here:


The filter gets a bean property traceIdHeaderName that is being populated by ObservationFilterConfigurations from a new property, something like management.observations.http.server.requests.trace-header-name=x-my-custom-trace-id-header-name.

We were just waiting for community feedback before expanding support.

I see, thank you.

@bclozel
Copy link
Member Author

bclozel commented Feb 26, 2025

@kzander91 but what would be the purpose of changing the header name? X-Trace-Id, traceresponse and Server-Timing all have different formats for the header value. What would be the goal?

@kzander91
Copy link
Contributor

Sorry, I missed that we're not just discussing header names, but also different header values (i.e. formats). I guess if we're using established header names, it would not make sense to make them customizable, you're right.

In my app, I have built a filter myself that exposes the trace id as a response header (under a name I have chosen myself). If this topic was just about exposing the trace id, and the header name was configurable, I could have replaced my own filter with Boot's new filter.

@bclozel
Copy link
Member Author

bclozel commented Feb 27, 2025

No worries @kzander91 I was just making sure I didn't miss anything.

As for the custom header that was our original intent but we got feedback and apparently that's not what people expect. Hopefully the "traceresponse" will be more adopted in the future.

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
@bclozel
Copy link
Member Author

bclozel commented Feb 27, 2025

Changes are now ready but on hold, as we are discussing with the Micrometer team whether this feature belongs in Micrometer directly.

@bclozel bclozel added status: on-hold We can't start working on this issue yet and removed status: pending-design-work Needs design work before any code can be developed labels Feb 27, 2025
@bclozel bclozel modified the milestones: 3.5.0-M3, 3.5.x Feb 28, 2025
@bclozel
Copy link
Member Author

bclozel commented Mar 25, 2025

The original attempt has been reverted in #44752. The "traceresponse" implementation is quite straightforward.

But it sounds like there is no strong consensus in the community nor in the industry about which header and format should be adopted for this. In the meantime, developers can override a protected method in the filter and contribute this as a bean, as seen in spring-projects/spring-framework#30632 (comment).

Depending on how things evolve, we might consider this as a Spring Boot feature or Micrometer feature in the future.

@bclozel bclozel modified the milestones: 3.5.x, General Backlog Mar 25, 2025
@shakuzen
Copy link
Member

Would users that are asking for this feature share some details about their use case? That may help us understand how to best deliver this feature and how generally applicable the need may be. I haven't seen much shared about the underlying need that's motivated this request.

@glyiu98
Copy link

glyiu98 commented Mar 28, 2025

I also have the same use case as @kzander91.
On my projects I am returning the traceId in the response headers for easier tracking.

I was also interested on having the choice of choosing a custom header name because I am using a service which expects a specific header name (different from the default you are proposing).

@bclozel
Copy link
Member Author

bclozel commented Mar 28, 2025

Thanks for your feedback @glyiu98 !

If you need a custom header format then you can achieve that already with #44431 (comment)
This issue wouldn't help at all in your case then.

I would be interested to learn more. Can you name the service that is using this header and which format it is expecting?

@glyiu98
Copy link

glyiu98 commented Mar 28, 2025

Yes indeed, that’s what we currently have in place.

We have that constraint because our infra team have setup some analytics events for the API calls which would look for the specific response header “Correlation-Id”, so it was more because of a custom configuration :D

@shakuzen
Copy link
Member

On my projects I am returning the traceId in the response headers for easier tracking.

I'm hoping to get more details about what that means. Presumably you're using a distributed tracing system, which doesn't use the trace ID in the response headers, so I'm wondering how it is being used. I presume it is some other system for some other purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: on-hold We can't start working on this issue yet type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants