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(zipkin) include http path to span name #8150

Merged
merged 6 commits into from
Apr 1, 2022
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@
- Bumped resty.openssl from 0.8.5 to 0.8.6
[#8545](https://github.com/Kong/kong/pull/8545)

### Additions

#### Plugins

- **Zipkin**: add support for including HTTP path in span name
through configuration property `http_span_name`.
[#8150](https://github.com/Kong/kong/pull/8150)

### Fixes

#### Core
Expand Down
10 changes: 8 additions & 2 deletions kong/plugins/zipkin/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,15 @@ if subsystem == "http" then
trace_id = rand_bytes(conf.traceid_byte_count)
end

local span_name = method
local path = req.get_path()
if conf.http_span_name == "method_path" then
span_name = method .. ' ' .. path
end

local request_span = new_span(
"SERVER",
method,
span_name,
ngx_req_start_time_mu(),
should_sample,
trace_id,
Expand All @@ -146,7 +152,7 @@ if subsystem == "http" then
request_span:set_tag("lc", "kong")
request_span:set_tag("http.method", method)
request_span:set_tag("http.host", req.get_host())
request_span:set_tag("http.path", req.get_path())
request_span:set_tag("http.path", path)
if protocol then
request_span:set_tag("http.protocol", protocol)
end
Expand Down
1 change: 1 addition & 0 deletions kong/plugins/zipkin/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ return {
{ tags_header = { type = "string", required = true, default = "Zipkin-Tags" } },
{ static_tags = { type = "array", elements = static_tag,
custom_validator = validate_static_tags } },
{ http_span_name = { type = "string", required = true, default = "method", one_of = { "method", "method_path" } } },
},
}, },
},
Expand Down
66 changes: 66 additions & 0 deletions spec/03-plugins/34-zipkin/zipkin_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,72 @@ for _, strategy in helpers.each_strategy() do
end


for _, strategy in helpers.each_strategy() do
describe("http_span_name configuration", function()
local proxy_client, zipkin_client, service

setup(function()
local bp = helpers.get_db_utils(strategy, { "services", "routes", "plugins" })

service = bp.services:insert {
name = string.lower("http-" .. utils.random_string()),
}

-- kong (http) mock upstream
bp.routes:insert({
name = string.lower("route-" .. utils.random_string()),
service = service,
hosts = { "http-route" },
preserve_host = true,
})

-- enable zipkin plugin globally, with sample_ratio = 1
bp.plugins:insert({
name = "zipkin",
config = {
sample_ratio = 1,
http_endpoint = fmt("http://%s:%d/api/v2/spans", ZIPKIN_HOST, ZIPKIN_PORT),
default_header_type = "b3-single",
http_span_name = "method_path",
}
})

helpers.start_kong({
database = strategy,
nginx_conf = "spec/fixtures/custom_nginx.template",
stream_listen = helpers.get_proxy_ip(false) .. ":19000",
})

proxy_client = helpers.proxy_client()
zipkin_client = helpers.http_client(ZIPKIN_HOST, ZIPKIN_PORT)
end)

teardown(function()
helpers.stop_kong()
end)

it("http_span_name = 'method_path' includes path to span name", function()
local start_s = ngx.now()

local r = proxy_client:get("/", {
headers = {
["x-b3-sampled"] = "1",
host = "http-route",
["zipkin-tags"] = "foo=bar; baz=qux"
},
})

assert.response(r).has.status(200)

local _, proxy_span, request_span =
wait_for_spans(zipkin_client, 3, service.name)
-- common assertions for request_span and proxy_span
assert_span_invariants(request_span, proxy_span, "get /", 16 * 2, start_s, "kong")
end)
end)
end


for _, strategy in helpers.each_strategy() do
for _, traceid_byte_count in ipairs({ 8, 16 }) do
describe("http integration tests with zipkin server [#"
Expand Down