From 4d613f2db5dc4c2a8a4271dbe64852333ffdbce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=B5=A9=E5=BD=AC?= Date: Tue, 19 Dec 2023 15:17:02 +0800 Subject: [PATCH 1/2] fix(zipkin): avoid getting a nil value in log phase(#10590) --- apisix/plugins/zipkin.lua | 14 +++++++++----- t/plugin/zipkin.t | 10 ++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/apisix/plugins/zipkin.lua b/apisix/plugins/zipkin.lua index efebd5115035..0b9efa8f2732 100644 --- a/apisix/plugins/zipkin.lua +++ b/apisix/plugins/zipkin.lua @@ -283,6 +283,15 @@ end function _M.log(conf, ctx) + if ctx.zipkin then + core.tablepool.release("zipkin_ctx", ctx.zipkin) + ctx.zipkin = nil + end + + if not ctx.opentracing_sample then + return + end + local opentracing = ctx.opentracing local log_end_time = opentracing.tracer:time() @@ -302,11 +311,6 @@ function _M.log(conf, ctx) opentracing.request_span:set_tag("http.status_code", upstream_status) opentracing.request_span:finish(log_end_time) - - if ctx.zipkin then - core.tablepool.release("zipkin_ctx", ctx.zipkin) - ctx.zipkin = nil - end end return _M diff --git a/t/plugin/zipkin.t b/t/plugin/zipkin.t index 39f7884d39e0..6f6500a0de17 100644 --- a/t/plugin/zipkin.t +++ b/t/plugin/zipkin.t @@ -467,3 +467,13 @@ GET /t --- response_body 1 0 + + + +=== TEST 23: no error in log phase while b3 header invalid +--- request +GET /echo +--- more_headers +b3: abc +--- no_error_log +[error] \ No newline at end of file From 5895771d7948e5d26774dc35c1f96bb83fc04b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=B5=A9=E5=BD=AC?= Date: Thu, 21 Dec 2023 14:30:05 +0800 Subject: [PATCH 2/2] fix(zipkin): add a new test case(#10590) --- t/plugin/zipkin.t | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/t/plugin/zipkin.t b/t/plugin/zipkin.t index 6f6500a0de17..a227f35c9e36 100644 --- a/t/plugin/zipkin.t +++ b/t/plugin/zipkin.t @@ -474,6 +474,11 @@ GET /t --- request GET /echo --- more_headers -b3: abc +b3: 80f198ee56343ba864fe8b2a57d3eff7 +--- response_headers +x-b3-sampled: +--- error_code: 400 +--- error_log +invalid b3 header --- no_error_log -[error] \ No newline at end of file +attempt to index local 'opentracing' (a nil value)