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

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

Merged
merged 7 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
[#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.
StarlightIbuki marked this conversation as resolved.
Show resolved Hide resolved
[#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