fix(tracer): ensure coroutine spans are closed and tagged on failure#7729
Open
wregis wants to merge 1 commit intohyperf:masterfrom
Open
fix(tracer): ensure coroutine spans are closed and tagged on failure#7729wregis wants to merge 1 commit intohyperf:masterfrom
wregis wants to merge 1 commit intohyperf:masterfrom
Conversation
a2851c8 to
df43a07
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a critical observability and memory management issue in the
hyperf/tracercomponent when tracing coroutines (CoroutineAspect).Motivation
Currently, if a coroutine executed via
Co::create()throws an unhandled exception or is abruptly terminated, the tracer span is never finished ($child->finish()) and never flushed ($tracer->flush()).This causes three main issues:
error=true) in the span, making troubleshooting difficult.Changes made
try/catch/finallyblock to capture exceptions, add theerrortag, and log the exception details to the span.Co::deferas a fallback to guarantee the span is closed even if the coroutine lifecycle is interrupted by flow-control functions likeCo::exit().\stdClassobject to keep track of the span'sfinishedstate. This prevents multiple executions offinish()/flush()and avoids using variable references (&$finished) inside closures, which is a known anti-pattern in Swoole and triggers static analysis warnings.Type of change