Skip to content

Commit

Permalink
feat: ignore existing trace (#125)
Browse files Browse the repository at this point in the history
Co-authored-by: Yoan Blanc <yblanc@edgelab.ch>
  • Loading branch information
kikito and greut authored Sep 6, 2021
1 parent 1784675 commit a61332b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion kong/plugins/zipkin/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ if subsystem == "http" then
local req_headers = req.get_headers()

local header_type, trace_id, span_id, parent_id, should_sample, baggage =
tracing_headers.parse(req_headers)
tracing_headers.parse(req_headers, conf.header_type)

local method = req.get_method()

if should_sample == nil then
Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/zipkin/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ return {
{ include_credential = { type = "boolean", required = true, default = true } },
{ 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" } } },
one_of = { "preserve", "ignore", "b3", "b3-single", "w3c", "jaeger", "ot" } } },
{ default_header_type = { type = "string", required = true, default = "b3",
one_of = { "b3", "b3-single", "w3c", "jaeger", "ot" } } },
{ tags_header = { type = "string", required = true, default = "Zipkin-Tags" } },
Expand Down
9 changes: 8 additions & 1 deletion kong/plugins/zipkin/tracing_headers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,11 @@ local function find_header_type(headers)
end


local function parse(headers)
local function parse(headers, conf_header_type)
if conf_header_type == "ignore" then
return nil
end

-- Check for B3 headers first
local header_type, composed_header = find_header_type(headers)
local trace_id, span_id, parent_id, should_sample
Expand Down Expand Up @@ -401,7 +405,10 @@ end
local function set(conf_header_type, found_header_type, proxy_span, conf_default_header_type)
local set_header = kong.service.request.set_header

-- If conf_header_type is set to `preserve`, found_header_type is used over default_header_type;
-- if conf_header_type is set to `ignore`, found_header_type is not set, thus default_header_type is used.
if conf_header_type ~= "preserve" and
conf_header_type ~= "ignore" and
found_header_type ~= nil and
conf_header_type ~= found_header_type
then
Expand Down
7 changes: 7 additions & 0 deletions spec/tracing_headers_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ describe("tracing_headers.parse", function()
warn:revert()
end)

it("does not parse headers with ignore type", function()
local b3 = fmt("%s-%s-%s-%s", trace_id, span_id, "1", parent_id)
local t = { parse({ tracestate = "b3=" .. b3 }, "ignore") }
assert.spy(warn).not_called()
assert.same({}, t)
end)

it("1-char", function()
local t = { parse({ b3 = "1" }) }
assert.same({ "b3-single", nil, nil, nil, true }, t)
Expand Down

0 comments on commit a61332b

Please sign in to comment.