Skip to content
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

Fix: http.client_ip vs multiple addresses #2282 #2284

Merged
merged 3 commits into from Oct 18, 2021

Conversation

garthk
Copy link
Contributor

@garthk garthk commented Oct 12, 2021

I took the example from the MDN docs for X-Forwarded-For.

Resolves #2282

Copy link
Contributor

@MadVikingGod MadVikingGod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

semconv/v1.4.0/http.go Outdated Show resolved Hide resolved
semconv/v1.4.0/http.go Outdated Show resolved Hide resolved
Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added one little change suggestion

@codecov
Copy link

codecov bot commented Oct 14, 2021

Codecov Report

Merging #2284 (4f70f09) into main (e9db047) will decrease coverage by 0.0%.
The diff coverage is 100.0%.

Impacted file tree graph

@@           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     
Impacted Files Coverage Δ
semconv/v1.4.0/http.go 95.1% <100.0%> (+<0.1%) ⬆️
...s/otlp/otlptrace/internal/connection/connection.go 14.6% <0.0%> (-1.6%) ⬇️
exporters/jaeger/jaeger.go 94.3% <0.0%> (+0.8%) ⬆️

@garthk
Copy link
Contributor Author

garthk commented Oct 14, 2021

@MadVikingGod I don't believe combining all the header values into one long string meets the specification. The HTTP Server Semantic Conventions describe http.client_ip as containing:

The IP address of the original client behind all proxies, if known (e.g. from X-Forwarded-For).

If they intended the value to contain the IP addresses of the original client and all proxies, I trust they would have said so.

Copy link
Contributor Author

@garthk garthk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@garthk
Copy link
Contributor Author

garthk commented Oct 14, 2021

The tests caught the regression 🎉

Rebased and fixed.

@pellared
Copy link
Member

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.

Sorry, my bad. It is good that we have unit tests 😄

@MrAlias MrAlias merged commit 2e6211e into open-telemetry:main Oct 18, 2021
@garthk garthk deleted the fix-2822-client_ip branch October 18, 2021 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

http.client_ip contains multiple addresses from X-Forwarded-For
6 participants