Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
feat(span-tag): add header x-request-id to span tag
Browse files Browse the repository at this point in the history
  • Loading branch information
carnei-ro committed Mar 24, 2021
1 parent 1e7db29 commit 8b55eb4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions kong/plugins/zipkin/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ if subsystem == "http" then
get_or_add_proxy_span(zipkin, access_start)

tracing_headers.set(conf.header_type, zipkin.header_type, zipkin.proxy_span, conf.default_header_type)

if conf.include_header_x_request_id then
local x_request_id = kong.request.get_header('x-request-id')
if x_request_id then
zipkin.request_span:set_tag(conf.tag_name_for_x_request_id, x_request_id)
end
end
end


Expand Down
3 changes: 3 additions & 0 deletions kong/plugins/zipkin/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ return {
between = { 0, 1 } } },
{ default_service_name = { type = "string", default = nil } },
{ include_credential = { type = "boolean", required = true, default = true } },
{ include_header_x_request_id = { type = "boolean", required = true, default = false } },
{ tag_name_for_x_request_id = { type = "string", required = true, default = "guid:x-request-id",
not_one_of = PROTECTED_TAGS } },
{ traceid_byte_count = { type = "integer", required = true, default = 16, one_of = { 8, 16 } } },
{ header_type = { type = "string", required = true, default = "preserve",
one_of = { "preserve", "b3", "b3-single", "w3c", "jaeger", "ot" } } },
Expand Down
11 changes: 10 additions & 1 deletion spec/zipkin_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ describe("http integration tests with zipkin server [#"
{ name = "static", value = "ok" },
},
default_header_type = "b3-single",
include_header_x_request_id = true,
}
})

Expand Down Expand Up @@ -221,12 +222,15 @@ describe("http integration tests with zipkin server [#"

it("generates spans, tags and annotations for regular requests", function()
local start_s = ngx.now()
local uuid = require("resty.jit-uuid")
local x_request_id = uuid.generate_v4()

local r = proxy_client:get("/", {
headers = {
["x-b3-sampled"] = "1",
host = "http-route",
["zipkin-tags"] = "foo=bar; baz=qux"
["zipkin-tags"] = "foo=bar; baz=qux",
["x-request-id"] = x_request_id
},
})
assert.response(r).has.status(200)
Expand All @@ -244,6 +248,7 @@ describe("http integration tests with zipkin server [#"
["http.method"] = "GET",
["http.path"] = "/",
["http.status_code"] = "200", -- found (matches server status)
["guid:x-request-id"] = x_request_id,
lc = "kong",
static = "ok",
foo = "bar",
Expand Down Expand Up @@ -292,6 +297,8 @@ describe("http integration tests with zipkin server [#"

it("generates spans, tags and annotations for regular requests (#grpc)", function()
local start_s = ngx.now()
local uuid = require("resty.jit-uuid")
local x_request_id = uuid.generate_v4()

local ok, resp = proxy_client_grpc({
service = "hello.HelloService.SayHello",
Expand All @@ -300,6 +307,7 @@ describe("http integration tests with zipkin server [#"
},
opts = {
["-H"] = "'x-b3-sampled: 1'",
["-H"] = "'x-request-id: " .. x_request_id .. "'",
["-authority"] = "grpc-route",
}
})
Expand All @@ -320,6 +328,7 @@ describe("http integration tests with zipkin server [#"
["http.method"] = "POST",
["http.path"] = "/hello.HelloService/SayHello",
["http.status_code"] = "200", -- found (matches server status)
["guid:x-request-id"] = x_request_id,
lc = "kong",
static = "ok",
}, request_tags)
Expand Down

0 comments on commit 8b55eb4

Please sign in to comment.