Skip to content

Commit

Permalink
feat(tracing): add http.client_ip attribute (#10723)
Browse files Browse the repository at this point in the history
* fix(tracing): use get_forwarded_ip instead of get_ip for peer IP

As a developer troubleshooting requests using trace data, I expect my access logs to be consistent with my traces. The access logs currently record the forwarded_ip, which tells me what my client's true ip is (assuming proper setup of trusted IPs etc). This change switches the span attribute for peer ip to use forwarded_ip as well.

* fix(tracing): add get_forwarded_ip as separate attribute

* fix(tracing): add new attribute to test case

* feat(tracing): add changelog entry
  • Loading branch information
backjo authored Apr 28, 2023
1 parent 0b19bbb commit 57b9ae6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@
- Request and response buffering options are now enabled for incoming HTTP 2.0 requests too.
Thanks [@PidgeyBE](https://github.com/PidgeyBE) for contributing this change.
[#10595](https://github.com/Kong/kong/pull/10595)
[#10204](https://github.com/Kong/kong/pull/10204)
[#10204](https://github.com/Kong/kong/pull/10204)
- Add `KONG_UPSTREAM_DNS_TIME` to `kong.ctx` so that we can record the time it takes for DNS
resolution when Kong proxies to upstream.
[#10355](https://github.com/Kong/kong/pull/10355)
- Tracing: rename spans to simplify filtering on tracing backends.
[#10577](https://github.com/Kong/kong/pull/10577)
- Support timeout for dynamic log level
[#10288](https://github.com/Kong/kong/pull/10288)
- Added new span attribute `http.client_ip` to capture the client IP when behind a proxy.
[#10723](https://github.com/Kong/kong/pull/10723)

#### Admin API

Expand Down
1 change: 1 addition & 0 deletions kong/tracing/instrumentation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ function _M.request(ctx)
["http.host"] = host,
["http.scheme"] = scheme,
["http.flavor"] = http_flavor,
["http.client_ip"] = client.get_forwarded_ip(),
["net.peer.ip"] = client.get_ip(),
},
})
Expand Down
1 change: 1 addition & 0 deletions spec/03-plugins/37-opentelemetry/04-exporter_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ for _, strategy in helpers.each_strategy() do
local attr = span.attributes
sort_by_key(attr)
assert.same({
{ key = "http.client_ip", value = { string_value = "127.0.0.1", value = "string_value" } },
{ key = "http.flavor", value = { string_value = "1.1", value = "string_value" } },
{ key = "http.host", value = { string_value = "0.0.0.0", value = "string_value" } },
{ key = "http.method", value = { string_value = "GET", value = "string_value" } },
Expand Down

1 comment on commit 57b9ae6

@khcp-gha-bot
Copy link

Choose a reason for hiding this comment

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

Bazel Build

Docker image available kong/kong:57b9ae669a97af128825538c109c2d71a4264618
Artifacts available https://github.com/Kong/kong/actions/runs/4829826003

Please sign in to comment.