This pull request addresses the behavior mentioned in the comment at here and here regarding adding the trace ID to the response header. By default, the code adds the X-Trace-ID header to the response, which might not be desirable for all users, especially when the WithTraceResponseHeaderKey option is not used.
To align with user expectations and improve flexibility, this PR modifies the code to only add the trace ID to the response header when the WithTraceResponseHeaderKey option is explicitly used. This change ensures that the response header is modified only when required, providing better control over the tracing behavior.
Changes:
Updated the ServeHTTP method in traceware to conditionally add the trace ID to the response header based on the usage of the WithTraceResponseHeaderKey option.
Added a check to verify if the tw.traceResponseHeaderKey is not empty before adding the trace ID to the response header.
Unit tests have been added/updated to validate the new behavior. Testing has been performed to ensure that the trace ID is only added to the response header when the WithTraceResponseHeaderKey option is used, and no unintended modifications are made otherwise.
This change enhances the usability and flexibility of the tracing middleware, allowing users to customize the tracing behavior more precisely based on their requirements.
This pull request addresses the behavior mentioned in the comment at here and here regarding adding the trace ID to the response header. By default, the code adds the X-Trace-ID header to the response, which might not be desirable for all users, especially when the WithTraceResponseHeaderKey option is not used.
To align with user expectations and improve flexibility, this PR modifies the code to only add the trace ID to the response header when the WithTraceResponseHeaderKey option is explicitly used. This change ensures that the response header is modified only when required, providing better control over the tracing behavior.
Changes:
This change enhances the usability and flexibility of the tracing middleware, allowing users to customize the tracing behavior more precisely based on their requirements.
Related Issue(s): Trace ID in header