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
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Fixed

- json stdout exporter no longer crashes due to concurrency bug. (#2265)
- `http.client_ip` no longer inhales multiple addresses from the `X-Forwarded-For` header. (#2282)

## [Metrics 0.24.0] - 2021-10-01

Expand Down
4 changes: 3 additions & 1 deletion semconv/v1.4.0/http.go
Expand Up @@ -225,7 +225,9 @@ func HTTPServerAttributesFromHTTPRequest(serverName, route string, request *http
attrs = append(attrs, HTTPRouteKey.String(route))
}
if values, ok := request.Header["X-Forwarded-For"]; ok && len(values) > 0 {
attrs = append(attrs, HTTPClientIPKey.String(values[0]))
if addresses := strings.SplitN(values[0], ",", 2); len(addresses) > 0 {
attrs = append(attrs, HTTPClientIPKey.String(addresses[0]))
}
}

return append(attrs, httpCommonAttributesFromHTTPRequest(request)...)
Expand Down
4 changes: 2 additions & 2 deletions semconv/v1.4.0/http_test.go
Expand Up @@ -585,7 +585,7 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) {
},
header: http.Header{
"User-Agent": []string{"foodownloader"},
"X-Forwarded-For": []string{"1.2.3.4"},
"X-Forwarded-For": []string{"203.0.113.195, 70.41.3.18, 150.172.238.178"},
MrAlias marked this conversation as resolved.
Show resolved Hide resolved
},
tls: withTLS,
expected: []attribute.KeyValue{
Expand All @@ -597,7 +597,7 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) {
attribute.String("http.route", "/user/:id"),
attribute.String("http.host", "example.com"),
attribute.String("http.user_agent", "foodownloader"),
attribute.String("http.client_ip", "1.2.3.4"),
attribute.String("http.client_ip", "203.0.113.195"),
},
},
{
Expand Down