mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-14 08:51:29 +08:00
parent
84ce7ba781
commit
d1fe72c0a0
@ -59,7 +59,25 @@ function _M.check_schema(conf)
|
||||
end
|
||||
|
||||
|
||||
local function create_tracer(conf)
|
||||
local function create_tracer(conf,ctx)
|
||||
|
||||
local headers = core.request.headers(ctx)
|
||||
|
||||
-- X-B3-Sampled: if an upstream decided to sample this request, we do too.
|
||||
local sample = headers["x-b3-sampled"]
|
||||
if sample == "1" or sample == "true" then
|
||||
conf.sample_ratio = 1
|
||||
elseif sample == "0" or sample == "false" then
|
||||
conf.sample_ratio = 0
|
||||
end
|
||||
|
||||
-- X-B3-Flags: if it equals '1' then it overrides sampling policy
|
||||
-- We still want to warn on invalid sample header, so do this after the above
|
||||
local debug = headers["x-b3-flags"]
|
||||
if debug == "1" then
|
||||
conf.sample_ratio = 1
|
||||
end
|
||||
|
||||
local tracer = new_tracer(new_reporter(conf), new_random_sampler(conf))
|
||||
tracer:register_injector("http_headers", zipkin_codec.new_injector())
|
||||
tracer:register_extractor("http_headers", zipkin_codec.new_extractor())
|
||||
@ -91,7 +109,7 @@ function _M.rewrite(plugin_conf, ctx)
|
||||
end
|
||||
|
||||
local tracer = core.lrucache.plugin_ctx(plugin_name .. '#' .. conf.server_addr, ctx,
|
||||
create_tracer, conf)
|
||||
create_tracer, conf, ctx)
|
||||
|
||||
ctx.opentracing_sample = tracer.sampler:sample()
|
||||
if not ctx.opentracing_sample then
|
||||
|
@ -35,26 +35,6 @@ end
|
||||
|
||||
local function new_extractor()
|
||||
return function(headers)
|
||||
-- X-B3-Sampled: if an upstream decided to sample this request, we do too.
|
||||
local sample = headers["x-b3-sampled"]
|
||||
if sample == "1" or sample == "true" then
|
||||
sample = true
|
||||
elseif sample == "0" or sample == "false" then
|
||||
sample = false
|
||||
elseif sample ~= nil then
|
||||
core.log.warn("x-b3-sampled header invalid; ignoring.")
|
||||
sample = nil
|
||||
end
|
||||
|
||||
-- X-B3-Flags: if it equals '1' then it overrides sampling policy
|
||||
-- We still want to warn on invalid sample header, so do this after the above
|
||||
local debug = headers["x-b3-flags"]
|
||||
if debug == "1" then
|
||||
sample = true
|
||||
elseif debug ~= nil then
|
||||
core.log.warn("x-b3-flags header invalid; ignoring.")
|
||||
end
|
||||
|
||||
local had_invalid_id = false
|
||||
|
||||
local trace_id = headers["x-b3-traceid"]
|
||||
@ -99,7 +79,7 @@ local function new_extractor()
|
||||
request_span_id = from_hex(request_span_id)
|
||||
|
||||
return new_span_context(trace_id, request_span_id, parent_span_id,
|
||||
sample, baggage)
|
||||
baggage)
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user