opentelemetry-java-instrumentation icon indicating copy to clipboard operation
opentelemetry-java-instrumentation copied to clipboard

Extend HttpServerResponseMutator with replace and set if absent variants

Open ddark008 opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe.

Current HttpServerResponseMutator provides only appending header values. In some circumstances, this can lead to duplicate header values. For example, the instrumentation of the spring-cloud-gateway proxy adds additional headers to all packets that are passed through, in addition to existing headers.

Describe the solution you'd like

Extend HttpServerResponseMutator with new methods:

  • replace existing headers
  • set header if absent

Describe alternatives you've considered

No response

Additional context

I can provide some PR to support these features

ddark008 avatar Apr 07 '24 08:04 ddark008

It looks good! @open-telemetry/java-instrumentation-approvers WDYT?

steverao avatar Apr 08 '24 01:04 steverao

I think this sounds reasonable. It will require some thought to determine which methods to add. For example if one wishes to modify the value for a header that can contain a comma separated list of values like https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers it would be handy to have access to the original value so instead of overwriting one could append to the existing value. Things are further complicated by the possibility of having the same header set multiple times.

laurit avatar Apr 18 '24 11:04 laurit