This is an automated email from the ASF dual-hosted git repository.

monkeydluffy 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 06aa25033 fix(zipkin): avoid getting a nil value in log phase (#10666)
06aa25033 is described below

commit 06aa2503392145ea94e72ece1de8fa4e426a51e5
Author: Junhao <38750962+junhao69...@users.noreply.github.com>
AuthorDate: Fri Dec 22 09:00:54 2023 +0800

    fix(zipkin): avoid getting a nil value in log phase (#10666)
---
 apisix/plugins/zipkin.lua | 14 +++++++++-----
 t/plugin/zipkin.t         | 15 +++++++++++++++
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/apisix/plugins/zipkin.lua b/apisix/plugins/zipkin.lua
index efebd5115..0b9efa8f2 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 39f7884d3..a227f35c9 100644
--- a/t/plugin/zipkin.t
+++ b/t/plugin/zipkin.t
@@ -467,3 +467,18 @@ GET /t
 --- response_body
 1
 0
+
+
+
+=== TEST 23: no error in log phase while b3 header invalid
+--- request
+GET /echo
+--- more_headers
+b3: 80f198ee56343ba864fe8b2a57d3eff7
+--- response_headers
+x-b3-sampled:
+--- error_code: 400
+--- error_log
+invalid b3 header
+--- no_error_log
+attempt to index local 'opentracing' (a nil value)

Reply via email to