diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0f7d23f..4ebb5d0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Create Release id: create_release uses: actions/create-release@v1 diff --git a/src/Adapter/Reporter/KafkaClientFactory.php b/src/Adapter/Reporter/KafkaClientFactory.php index 344080b..4a6cf8a 100644 --- a/src/Adapter/Reporter/KafkaClientFactory.php +++ b/src/Adapter/Reporter/KafkaClientFactory.php @@ -22,6 +22,8 @@ use Throwable; use Zipkin\Reporters\Http\ClientFactory; +use function Hyperf\Support\msleep; + class KafkaClientFactory implements ClientFactory { protected ?Channel $chan = null; @@ -93,7 +95,10 @@ protected function loop(): void try { $closure->call($this); } catch (Throwable) { - $this->producer->close(); + try { + $this->producer->close(); + } catch (Throwable) { + } break; } finally { $closure = null; @@ -106,6 +111,9 @@ protected function loop(): void Coroutine::create(function () { if (CoordinatorManager::until(Constants::WORKER_EXIT)->yield()) { + while (! $this->chan->isEmpty()) { + msleep(100); + } $this->close(); } }); diff --git a/src/Aspect/CoroutineAspect.php b/src/Aspect/CoroutineAspect.php index 557000c..96a381a 100644 --- a/src/Aspect/CoroutineAspect.php +++ b/src/Aspect/CoroutineAspect.php @@ -14,6 +14,7 @@ use Hyperf\Di\Aop\AbstractAspect; use Hyperf\Di\Aop\ProceedingJoinPoint; use Hyperf\Engine\Coroutine as Co; +use Hyperf\Tracer\SwitchManager; use Hyperf\Tracer\TracerContext; use OpenTracing\Span; use Throwable; @@ -24,6 +25,10 @@ class CoroutineAspect extends AbstractAspect 'Hyperf\Coroutine\Coroutine::create', ]; + public function __construct(private SwitchManager $switchManager) + { + } + public function process(ProceedingJoinPoint $proceedingJoinPoint) { $callable = $proceedingJoinPoint->arguments['keys']['callable']; @@ -46,7 +51,7 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) $callable(); } catch (Throwable $e) { - if (isset($child)) { + if (isset($child) && $this->switchManager->isEnable('exception') && ! $this->switchManager->isIgnoreException($e::class)) { $child->setTag('error', true); $child->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]); } diff --git a/src/Aspect/DbAspect.php b/src/Aspect/DbAspect.php index cea9ca0..701e2f2 100644 --- a/src/Aspect/DbAspect.php +++ b/src/Aspect/DbAspect.php @@ -46,8 +46,10 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) try { $result = $proceedingJoinPoint->process(); } catch (Throwable $e) { - $span->setTag('error', true); - $span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]); + if ($this->switchManager->isEnable('exception') && ! $this->switchManager->isIgnoreException($e::class)) { + $span->setTag('error', true); + $span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]); + } throw $e; } finally { $span->finish(); diff --git a/src/Aspect/ElasticserachAspect.php b/src/Aspect/ElasticserachAspect.php index 8cf21ce..7d1eac1 100644 --- a/src/Aspect/ElasticserachAspect.php +++ b/src/Aspect/ElasticserachAspect.php @@ -53,8 +53,10 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) try { $result = $proceedingJoinPoint->process(); } catch (Throwable $e) { - $span->setTag('error', true); - $span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]); + if ($this->switchManager->isEnable('exception') && ! $this->switchManager->isIgnoreException($e::class)) { + $span->setTag('error', true); + $span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]); + } throw $e; } finally { $span->finish(); diff --git a/src/Aspect/HttpClientAspect.php b/src/Aspect/HttpClientAspect.php index 93b3750..036873d 100644 --- a/src/Aspect/HttpClientAspect.php +++ b/src/Aspect/HttpClientAspect.php @@ -80,8 +80,10 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) $span->setTag($this->spanTagManager->get('http_client', 'http.status_code'), $result->getStatusCode()); } } catch (Throwable $e) { - $span->setTag('error', true); - $span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]); + if ($this->switchManager->isEnable('exception') && ! $this->switchManager->isIgnoreException($e::class)) { + $span->setTag('error', true); + $span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]); + } throw $e; } finally { $span->finish(); diff --git a/src/Aspect/JsonRpcAspect.php b/src/Aspect/JsonRpcAspect.php index 07f2459..7d1599c 100644 --- a/src/Aspect/JsonRpcAspect.php +++ b/src/Aspect/JsonRpcAspect.php @@ -74,7 +74,7 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) try { $result = $proceedingJoinPoint->process(); } catch (Throwable $e) { - if ($span = CT::get('tracer.span.' . static::class)) { + if (($span = CT::get('tracer.span.' . static::class)) && $this->switchManager->isEnable('exception') && ! $this->switchManager->isIgnoreException($e::class)) { $span->setTag('error', true); $span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]); CT::set('tracer.span.' . static::class, $span); diff --git a/src/Aspect/MethodAspect.php b/src/Aspect/MethodAspect.php index bf6ce00..72f5832 100644 --- a/src/Aspect/MethodAspect.php +++ b/src/Aspect/MethodAspect.php @@ -43,8 +43,10 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) try { $result = $proceedingJoinPoint->process(); } catch (Throwable $e) { - $span->setTag('error', true); - $span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]); + if ($this->switchManager->isEnable('exception') && ! $this->switchManager->isIgnoreException($e::class)) { + $span->setTag('error', true); + $span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]); + } throw $e; } finally { $span->finish(); diff --git a/src/Aspect/RedisAspect.php b/src/Aspect/RedisAspect.php index 409e36e..0b537de 100644 --- a/src/Aspect/RedisAspect.php +++ b/src/Aspect/RedisAspect.php @@ -47,8 +47,10 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) $result = $proceedingJoinPoint->process(); $span->setTag($this->spanTagManager->get('redis', 'result'), json_encode($result)); } catch (Throwable $e) { - $span->setTag('error', true); - $span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]); + if ($this->switchManager->isEnable('exception') && ! $this->switchManager->isIgnoreException($e::class)) { + $span->setTag('error', true); + $span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]); + } throw $e; } finally { $span->finish(); diff --git a/src/Aspect/TraceAnnotationAspect.php b/src/Aspect/TraceAnnotationAspect.php index 4d9bf83..c17279a 100644 --- a/src/Aspect/TraceAnnotationAspect.php +++ b/src/Aspect/TraceAnnotationAspect.php @@ -15,6 +15,7 @@ use Hyperf\Di\Aop\ProceedingJoinPoint; use Hyperf\Tracer\Annotation\Trace; use Hyperf\Tracer\SpanStarter; +use Hyperf\Tracer\SwitchManager; use Throwable; class TraceAnnotationAspect extends AbstractAspect @@ -25,7 +26,7 @@ class TraceAnnotationAspect extends AbstractAspect Trace::class, ]; - public function __construct() + public function __construct(private SwitchManager $switchManager) { } @@ -49,8 +50,10 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) try { $result = $proceedingJoinPoint->process(); } catch (Throwable $e) { - $span->setTag('error', true); - $span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]); + if ($this->switchManager->isEnable('exception') && ! $this->switchManager->isIgnoreException($e::class)) { + $span->setTag('error', true); + $span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]); + } throw $e; } finally { $span->finish();