AlinsRan commented on code in PR #12686:
URL: https://github.com/apache/apisix/pull/12686#discussion_r2762444852


##########
apisix/ssl/router/radixtree_sni.lua:
##########
@@ -177,9 +179,10 @@ function _M.match_and_set(api_ctx, match_only, alt_sni)
             -- with it sometimes
             core.log.error("failed to find any SSL certificate by SNI: ", sni)
         end
+        tracer.finish(api_ctx.ngx_ctx, tracer.status.ERROR, "failed match SNI")
         return false
     end
-
+    tracer.finish(api_ctx.ngx_ctx)

Review Comment:
   
   In APISIX, explicitly managing span hierarchies is not practical, especially 
across multiple modules. The management cost is high and error-prone: if a 
child span misses a `finish` call, all subsequent spans may be attached to the 
wrong parent.
   
   To address this, the model is adjusted to be centered around `current_span`.
   `tracer.start` only updates the current execution point (`current_span`), 
while `tracer.finish(span)` recursively finishes all child spans of the given 
span. This avoids hierarchy corruption caused by missing `finish` calls on 
child spans.
   
   Example behavior:
   
   ```lua
   -- current_span --> parent
   local parent = tracer.start("parent")
   -- current_span --> child
   local child = tracer.start("child")
   
   -- child missing finish
   
   -- finishing parent will automatically finish child
   tracer.finish(parent)
   ```
   
   This approach keeps the span hierarchy consistent without increasing the 
complexity for callers.
   
   And it is pluggable, so when detailed tracing is not enabled, there is no 
need to make additional redundant judgments when calling start/minimize.



-- 
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