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

feat(*) w3c trace context with expanded tracing header control #75

Merged
merged 2 commits into from
Apr 22, 2020
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
2 changes: 1 addition & 1 deletion kong-plugin-zipkin-1.0.0-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ build = {
["kong.plugins.zipkin.handler"] = "kong/plugins/zipkin/handler.lua",
["kong.plugins.zipkin.reporter"] = "kong/plugins/zipkin/reporter.lua",
["kong.plugins.zipkin.span"] = "kong/plugins/zipkin/span.lua",
["kong.plugins.zipkin.parse_http_req_headers"] = "kong/plugins/zipkin/parse_http_req_headers.lua",
["kong.plugins.zipkin.tracing_headers"] = "kong/plugins/zipkin/tracing_headers.lua",
["kong.plugins.zipkin.schema"] = "kong/plugins/zipkin/schema.lua",
},
}
29 changes: 5 additions & 24 deletions kong/plugins/zipkin/handler.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
local new_zipkin_reporter = require "kong.plugins.zipkin.reporter".new
local new_span = require "kong.plugins.zipkin.span".new
local to_hex = require "resty.string".to_hex
local parse_http_req_headers = require "kong.plugins.zipkin.parse_http_req_headers"
local utils = require "kong.tools.utils"

local tracing_headers = require "kong.plugins.zipkin.tracing_headers"

local subsystem = ngx.config.subsystem
local fmt = string.format
Expand Down Expand Up @@ -104,8 +102,8 @@ if subsystem == "http" then
initialize_request = function(conf, ctx)
local req = kong.request

local trace_id, span_id, parent_id, should_sample, baggage =
parse_http_req_headers(req.get_headers())
local header_type, trace_id, span_id, parent_id, should_sample, baggage =
tracing_headers.parse(req.get_headers())
local method = req.get_method()

if should_sample == nil then
Expand Down Expand Up @@ -135,6 +133,7 @@ if subsystem == "http" then

ctx.zipkin = {
request_span = request_span,
header_type = header_type,
proxy_span = nil,
header_filter_finished = false,
}
Expand All @@ -161,25 +160,7 @@ if subsystem == "http" then
or ngx_now_mu()
get_or_add_proxy_span(zipkin, access_start)

-- Want to send headers to upstream
local proxy_span = zipkin.proxy_span
local set_header = kong.service.request.set_header
-- We want to remove headers if already present
set_header("x-b3-traceid", to_hex(proxy_span.trace_id))
set_header("x-b3-spanid", to_hex(proxy_span.span_id))
if proxy_span.parent_id then
set_header("x-b3-parentspanid", to_hex(proxy_span.parent_id))
end
local Flags = kong.request.get_header("x-b3-flags") -- Get from request headers
if Flags then
set_header("x-b3-flags", Flags)
else
set_header("x-b3-sampled", proxy_span.should_sample and "1" or "0")
end
for key, value in proxy_span:each_baggage_item() do
-- XXX: https://github.com/opentracing/specification/issues/117
set_header("uberctx-"..key, ngx.escape_uri(value))
end
tracing_headers.set(conf.header_type, zipkin.header_type, zipkin.proxy_span)
end


Expand Down
182 changes: 0 additions & 182 deletions kong/plugins/zipkin/parse_http_req_headers.lua

This file was deleted.

2 changes: 2 additions & 0 deletions kong/plugins/zipkin/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ return {
{ default_service_name = { type = "string", default = nil } },
{ 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" } } },
},
}, },
},
Expand Down
Loading