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 ded7c44  fix(zipkin): response_span doesn't have correct start time 
(#5295)
ded7c44 is described below

commit ded7c44393e734ef00e6b2dbb999d6596384d744
Author: jackfu <[email protected]>
AuthorDate: Sun Oct 24 19:07:42 2021 +0800

    fix(zipkin): response_span doesn't have correct start time (#5295)
    
    Co-authored-by: jack.fu <[email protected]>
---
 apisix/plugins/zipkin.lua |  5 ++---
 t/plugin/zipkin2.t        | 25 +++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/apisix/plugins/zipkin.lua b/apisix/plugins/zipkin.lua
index e292b62..361f2c7 100644
--- a/apisix/plugins/zipkin.lua
+++ b/apisix/plugins/zipkin.lua
@@ -240,15 +240,14 @@ function _M.header_filter(conf, ctx)
     local end_time = opentracing.tracer:time()
 
     if conf.span_version == ZIPKIN_SPAN_VER_1 then
-        ctx.HEADER_FILTER_END_TIME = end_time
         if  opentracing.proxy_span then
             opentracing.body_filter_span = 
opentracing.proxy_span:start_child_span(
-                "apisix.body_filter", ctx.HEADER_FILTER_END_TIME)
+                "apisix.body_filter", end_time)
         end
     else
         opentracing.proxy_span:finish(end_time)
         opentracing.response_span = opentracing.request_span:start_child_span(
-            "apisix.response_span", ctx.HEADER_FILTER_END_TIME)
+            "apisix.response_span", end_time)
     end
 end
 
diff --git a/t/plugin/zipkin2.t b/t/plugin/zipkin2.t
index 7b0edef..9840092 100644
--- a/t/plugin/zipkin2.t
+++ b/t/plugin/zipkin2.t
@@ -31,6 +31,25 @@ add_block_preprocessor(sub {
     if (!$block->no_error_log && !$block->error_log) {
         $block->set_value("no_error_log", "[error]\n[alert]");
     }
+
+    my $extra_init_by_lua = <<_EOC_;
+    local new = require("opentracing.tracer").new
+    local tracer_mt = getmetatable(new()).__index
+    local orig_func = tracer_mt.start_span
+    tracer_mt.start_span = function (...)
+        local orig = orig_func(...)
+        local mt = getmetatable(orig).__index
+        local old_start_child_span = mt.start_child_span
+        mt.start_child_span = function(self, name, time)
+            ngx.log(ngx.WARN, "zipkin start_child_span ", name, " time: ", 
time)
+            return old_start_child_span(self, name, time)
+        end
+        return orig
+    end
+_EOC_
+
+    $block->set_value("extra_init_by_lua", $extra_init_by_lua);
+
 });
 
 run_tests;
@@ -83,6 +102,9 @@ x-b3-sampled: 1
 b3:
 --- error_log
 new span context: trace id: 80f198ee56343ba864fe8b2a57d3eff7, span id: 
e457b5a2e4d86bd1, parent span id: 05e3ac9a4f6e3b90
+--- grep_error_log eval
+qr/zipkin start_child_span apisix.response_span time: nil/
+--- grep_error_log_out
 
 
 
@@ -186,3 +208,6 @@ GET /t
 --- request
 GET /opentracing
 --- wait: 10
+--- grep_error_log eval
+qr/zipkin start_child_span apisix.response_span time: nil/
+--- grep_error_log_out

Reply via email to