diff --git a/CHANGELOG.md b/CHANGELOG.md index c614efef5a68..77e5f679ece1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/kong/plugins/zipkin/handler.lua b/kong/plugins/zipkin/handler.lua index ecde2896a77c..0b6c501a7bd9 100644 --- a/kong/plugins/zipkin/handler.lua +++ b/kong/plugins/zipkin/handler.lua @@ -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, @@ -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 diff --git a/kong/plugins/zipkin/schema.lua b/kong/plugins/zipkin/schema.lua index 9138d2b5df94..4a9b576a4a63 100644 --- a/kong/plugins/zipkin/schema.lua +++ b/kong/plugins/zipkin/schema.lua @@ -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" } } }, }, }, }, }, diff --git a/spec/03-plugins/34-zipkin/zipkin_spec.lua b/spec/03-plugins/34-zipkin/zipkin_spec.lua index 887ed7e968e4..eab8cba20377 100644 --- a/spec/03-plugins/34-zipkin/zipkin_spec.lua +++ b/spec/03-plugins/34-zipkin/zipkin_spec.lua @@ -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 [#"