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(tracing): record http.status_code when request is not proxied #11406

Merged
merged 3 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@
[#11066](https://github.com/Kong/kong/pull/11066)
- Fix a bug that caused sampling rate to be applied to individual spans producing split traces.
[#11135](https://github.com/Kong/kong/pull/11135)
- Fix a bug that caused spans to not be instrumented with http.status_code when the request was not proxied to an upstream.
Thanks [@backjo](https://github.com/backjo) for contributing this change.
[#11152](https://github.com/Kong/kong/pull/11152),
[#11406](https://github.com/Kong/kong/pull/11406)
- Fix a bug that caused the router to fail in `traditional_compatible` mode when a route with multiple paths and no service was created.
[#11158](https://github.com/Kong/kong/pull/11158)
- Fix an issue where the router of flavor `expressions` can not work correctly
Expand Down
1 change: 1 addition & 0 deletions kong/runloop/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,7 @@ return {
header_filter = {
before = function(ctx)
if not ctx.KONG_PROXIED then
instrumentation.runloop_before_header_filter(ngx.status)
return
end

Expand Down
50 changes: 49 additions & 1 deletion spec/02-integration/14-tracing/01-instrumentations_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ for _, strategy in helpers.each_strategy() do
hosts = { "status" },
strip_path = false })

local np_route = bp.routes:insert({
service = http_srv,
protocols = { "http" },
paths = { "/noproxy" },
strip_path = false
})

bp.plugins:insert({
name = tcp_trace_plugin_name,
config = {
Expand All @@ -74,10 +81,19 @@ for _, strategy in helpers.each_strategy() do
}
})

bp.plugins:insert({
name = "request-termination",
route = np_route,
config = {
status_code = 418,
message = "No coffee for you. I'm a teapot.",
}
})

assert(helpers.start_kong {
database = strategy,
nginx_conf = "spec/fixtures/custom_nginx.template",
plugins = "tcp-trace-exporter",
plugins = "bundled, tcp-trace-exporter",
tracing_instrumentations = types,
tracing_sampling_rate = 1,
})
Expand Down Expand Up @@ -316,6 +332,38 @@ for _, strategy in helpers.each_strategy() do
assert_has_no_span("kong.dns", spans)
assert_has_no_span("kong.rewrite.plugin." .. tcp_trace_plugin_name, spans)
end)

it("contains the expected kong span with status code when request is not proxied", function ()
local thread = helpers.tcp_server(TCP_PORT)
local r = assert(proxy_client:send {
method = "GET",
path = "/noproxy",
})
assert.res_status(418, r)

-- Getting back the TCP server input
local ok, res = thread:join()
assert.True(ok)
assert.is_string(res)

-- Making sure it's alright
local spans = cjson.decode(res)
local kong_span = assert_has_span("kong", spans)

assert_has_attributes(kong_span, {
["http.method"] = "GET",
["http.flavor"] = "1.1",
["http.status_code"] = "418",
["http.route"] = "/noproxy",
["http.url"] = "http://0.0.0.0/noproxy",
})
assert_has_span("kong.header_filter.plugin." .. tcp_trace_plugin_name, spans)
assert_has_no_span("kong.balancer", spans)
assert_has_no_span("kong.database.query", spans)
assert_has_no_span("kong.router", spans)
assert_has_no_span("kong.dns", spans)
assert_has_no_span("kong.rewrite.plugin." .. tcp_trace_plugin_name, spans)
end)
end)


Expand Down