akashchamp commented on code in PR #13985:
URL: https://github.com/apache/apisix/pull/13985#discussion_r4348295635


##########
apisix/plugins/opentelemetry.lua:
##########
@@ -451,6 +452,20 @@ function _M.rewrite(conf, api_ctx)
 end
 
 
+-- the vendored opentelemetry-lua's batch_span_processor falls back to a
+-- synchronous flush (opening a cosocket) when it fails to schedule the
+-- background timer, which happens near the end of every worker shutdown;
+-- that synchronous call trips APISIX's own phase guard (patch.lua) when
+-- span:finish() runs inside a restricted phase like log_by_lua*, so guard
+-- it here as defense in depth (see opentelemetry-lua#106/#107 upstream)
+local function finish_span(span, end_time)
+    local ok, err = pcall(span.finish, span, end_time)
+    if not ok then
+        core.log.warn("failed to finish opentelemetry span, ignore error: ", 
err)
+    end

Review Comment:
   Added a regression test in t/plugin/opentelemetry7.t (TEST 3): it makes the 
span processor's on_end raise and checks the guard logs a warning with no 
[error] for both the root and a child span. I couldn't run Test::Nginx locally 
(no OpenResty here), so it relies on CI.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to