You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2022/09/02 05:51:59 UTC
[apisix] branch master updated: fix(zipkin): send trace IDs with a reject sampling decision (#7833)
This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 859390084 fix(zipkin): send trace IDs with a reject sampling decision (#7833)
859390084 is described below
commit 8593900844eb45d0889d6cae910ac52f1d20c38f
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Fri Sep 2 13:51:49 2022 +0800
fix(zipkin): send trace IDs with a reject sampling decision (#7833)
---
apisix/plugins/zipkin.lua | 8 ++++++++
t/plugin/zipkin2.t | 7 +++++++
2 files changed, 15 insertions(+)
diff --git a/apisix/plugins/zipkin.lua b/apisix/plugins/zipkin.lua
index 3fafd29f0..ab284cefe 100644
--- a/apisix/plugins/zipkin.lua
+++ b/apisix/plugins/zipkin.lua
@@ -127,6 +127,8 @@ function _M.rewrite(plugin_conf, ctx)
local b3 = headers["b3"]
if b3 then
-- don't pass b3 header by default
+ -- TODO: add an option like 'single_b3_header' so we can adapt to the upstream
+ -- which doesn't support b3 header without always breaking down the header
core.request.set_header(ctx, "b3", nil)
local err
@@ -158,6 +160,12 @@ function _M.rewrite(plugin_conf, ctx)
ctx.opentracing_sample = tracer.sampler:sample(per_req_sample_ratio or conf.sample_ratio)
if not ctx.opentracing_sample then
core.request.set_header(ctx, "x-b3-sampled", "0")
+ -- pass the trace ids even the sample is rejected
+ -- see https://github.com/openzipkin/b3-propagation#why-send-
+ -- trace-ids-with-a-reject-sampling-decision
+ core.request.set_header(ctx, "x-b3-traceid", trace_id)
+ core.request.set_header(ctx, "x-b3-parentspanid", parent_span_id)
+ core.request.set_header(ctx, "x-b3-spanid", request_span_id)
return
end
diff --git a/t/plugin/zipkin2.t b/t/plugin/zipkin2.t
index 3175075d3..8423f6f67 100644
--- a/t/plugin/zipkin2.t
+++ b/t/plugin/zipkin2.t
@@ -98,6 +98,7 @@ passed
b3: 80f198ee56343ba864fe8b2a57d3eff7-e457b5a2e4d86bd1-1-05e3ac9a4f6e3b90
--- response_headers
x-b3-sampled: 1
+x-b3-traceid: 80f198ee56343ba864fe8b2a57d3eff7
--- raw_response_headers_unlike
b3:
--- error_log
@@ -124,6 +125,9 @@ invalid b3 header
b3: 80f198ee56343ba864fe8b2a57d3eff7-e457b5a2e4d86bd1-0-05e3ac9a4f6e3b90
--- response_headers
x-b3-sampled: 0
+x-b3-traceid: 80f198ee56343ba864fe8b2a57d3eff7
+x-b3-parentspanid: 05e3ac9a4f6e3b90
+x-b3-spanid: e457b5a2e4d86bd1
@@ -132,6 +136,9 @@ x-b3-sampled: 0
b3: 0
--- response_headers
x-b3-sampled: 0
+x-b3-traceid:
+x-b3-parentspanid:
+x-b3-spanid: