Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(zipkin): response_span doesn't have correct start time #5295

Merged
merged 21 commits into from
Oct 24, 2021
Merged

fix(zipkin): response_span doesn't have correct start time #5295

merged 21 commits into from
Oct 24, 2021

Conversation

zuiyangqingzhou
Copy link
Contributor

fix: #5294

What this PR does / why we need it:

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@spacewander spacewander changed the title fix zipkin plugin logic bug fix(zipkin): response_span doesn't have correct start time Oct 21, 2021
Copy link
Member

@spacewander spacewander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide a test case? You can hook the "start_child_span" to check if a valid time is given.
You can refer

local inject = function(mod, name)

@zuiyangqingzhou
Copy link
Contributor Author

Could you provide a test case? You can hook the "start_child_span" to check if a valid time is given. You can refer

local inject = function(mod, name)

OK

@zuiyangqingzhou
Copy link
Contributor Author

Could you provide a test case? You can hook the "start_child_span" to check if a valid time is given. You can refer

local inject = function(mod, name)

sorry, after trying many ways, I still don't understand how to hook the start_child_span, can you help me? @spacewander

@spacewander
Copy link
Member

You can apply this patch:

diff --git t/plugin/zipkin2.t t/plugin/zipkin2.t
index 7b0edef5..f7d4b55e 100644
--- t/plugin/zipkin2.t
+++ t/plugin/zipkin2.t
@@ -31,6 +31,24 @@ 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 +101,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 +207,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

@zuiyangqingzhou
Copy link
Contributor Author

You can apply this patch:

diff --git t/plugin/zipkin2.t t/plugin/zipkin2.t
index 7b0edef5..f7d4b55e 100644
--- t/plugin/zipkin2.t
+++ t/plugin/zipkin2.t
@@ -31,6 +31,24 @@ 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 +101,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 +207,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

Thank you

@spacewander spacewander merged commit ded7c44 into apache:master Oct 24, 2021
@zuiyangqingzhou zuiyangqingzhou deleted the fix-zipkin-plugin branch October 24, 2021 11:46
spacewander pushed a commit to spacewander/incubator-apisix that referenced this pull request Oct 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: the zipkin plugin has a logic bug in the header_filter phase
3 participants