Skip to content

Commit

Permalink
feat(tracing): add net.peer.name attribute if balancer_data.hostname …
Browse files Browse the repository at this point in the history
…is available (#10729)

* feat(tracing): add net.peer.name attribute if balancer_data.hostname is available

This records the upstream hostname if available on the balancer spans.

* add test check for new span attribute net.peer.name

* add changelog entry

* Update CHANGELOG.md

Co-authored-by: Chrono <[email protected]>

---------

Co-authored-by: Xumin <[email protected]>
Co-authored-by: Chrono <[email protected]>
  • Loading branch information
3 people authored Jul 18, 2023
1 parent f5685a9 commit c657a2c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
[#11082](https://github.com/Kong/kong/pull/11082)
- Fix an issue where the router of flavor `expressions` can not configure https redirection.
[#11166](https://github.com/Kong/kong/pull/11166)
- Added new span attribute `net.peer.name` if balancer_data.hostname is available.
Thanks [@backjo](https://github.com/backjo) for contributing this change.
[#10723](https://github.com/Kong/kong/pull/10729)

#### Admin API

Expand Down
8 changes: 8 additions & 0 deletions kong/tracing/instrumentation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ function _M.balancer(ctx)
span:set_attribute("http.status_code", try.code)
span:set_status(2)
end

if balancer_data.hostname ~= nil then
span:set_attribute("net.peer.name", balancer_data.hostname)
end

if try.balancer_latency_ns ~= nil then
local try_upstream_connect_time = (tonumber(upstream_connect_time[i], 10) or 0) * 1000
Expand All @@ -128,6 +132,10 @@ function _M.balancer(ctx)
span:set_attribute("http.status_code", try.code)
span:set_status(2)
end

if balancer_data.hostname ~= nil then
span:set_attribute("net.peer.name", balancer_data.hostname)
end

local upstream_finish_time = ctx.KONG_BODY_FILTER_ENDED_AT_NS
span:finish(upstream_finish_time)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ for _, strategy in helpers.each_strategy() do
assert_has_attributes(balancer_span, {
["net.peer.ip"] = "127.0.0.1",
["net.peer.port"] = "%d+",
["net.peer.name"] = "127.0.0.1",
})

assert_has_attributes(db_span, {
Expand Down

1 comment on commit c657a2c

@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:c657a2c4314144ea8e14874f7cad303e46325880
Artifacts available https://github.com/Kong/kong/actions/runs/5587782894

Please sign in to comment.