Fix: http.client_ip vs multiple addresses #2282#2284
Fix: http.client_ip vs multiple addresses #2282#2284MrAlias merged 3 commits intoopen-telemetry:mainfrom
Conversation
MadVikingGod
left a comment
There was a problem hiding this comment.
The current behavior is to take whatever is returned by the first value. You have changed it so that if we get a header that has multiple values we only take the first.
I've not used this field much, but do you have any examples of why we shouldn't be moving the opposite direction? By which I mean try and combine all of the header fields into one long string?
Codecov Report
@@ Coverage Diff @@
## main #2284 +/- ##
=======================================
- Coverage 72.6% 72.6% -0.1%
=======================================
Files 172 172
Lines 11918 11919 +1
=======================================
Hits 8661 8661
Misses 3023 3023
- Partials 234 235 +1
|
|
@MadVikingGod I don't believe combining all the header values into one long string meets the specification. The HTTP Server Semantic Conventions describe
If they intended the value to contain the IP addresses of the original client and all proxies, I trust they would have said so. |
There was a problem hiding this comment.
Wait up: I shouldn't have accepted the suggestion without checking I understood the semantics. As shown in this play.golang.org example with n=1 we'll end up with all the addresses, every time. This is by the design of strings.SplitN. From the docs:
SplitN slices s into substrings separated by sep and returns a slice of the substrings between those separators.
The count determines the number of substrings to return:
n > 0: at most n substrings; the last substring will be the unsplit remainder.
Instead we must call strings.SplitN with n=2.
As suggested by @pellared. Good suggestion, that. Co-authored-by: Robert Pająk <pellared@hotmail.com>
c9b30e0 to
e4e4e7c
Compare
|
The tests caught the regression 🎉 Rebased and fixed. |
Sorry, my bad. It is good that we have unit tests 😄 |
I took the example from the MDN docs for X-Forwarded-For.
Resolves #2282