in kong/kong/plugins/zipkin/handler.lua [120:193]
initialize_request = function(conf, ctx)
local req = kong.request
local req_headers = req.get_headers()
local header_type, trace_id, span_id, parent_id, should_sample, baggage =
propagation.parse(req_headers, conf.header_type)
local method = req.get_method()
if should_sample == nil then
should_sample = math_random() < conf.sample_ratio
end
if trace_id == nil 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",
span_name,
ngx_req_start_time_mu(),
should_sample,
trace_id,
span_id,
parent_id,
baggage)
local http_version = req.get_http_version()
local protocol = http_version and 'HTTP/'..http_version or nil
request_span.ip = kong.client.get_forwarded_ip()
request_span.port = kong.client.get_forwarded_port()
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", path)
if protocol then
request_span:set_tag("http.protocol", protocol)
end
local static_tags = conf.static_tags
if type(static_tags) == "table" then
for i = 1, #static_tags do
local tag = static_tags[i]
request_span:set_tag(tag.name, tag.value)
end
end
local req_tags, err = request_tags.parse(req_headers[conf.tags_header])
if err then
kong.log.warn(err)
end
if req_tags then
for tag_name, tag_value in pairs(req_tags) do
request_span:set_tag(tag_name, tag_value)
end
end
ctx.zipkin = {
request_span = request_span,
header_type = header_type,
proxy_span = nil,
header_filter_finished = false,
}
end