Skip to content

Commit

Permalink
Merge branch 'master' into 3.1
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/test.yml
#	src/service-governance/src/Listener/RegisterServiceListener.php
#	src/stringable/composer.json
#	src/stringable/tests/StrTest.php
  • Loading branch information
limingxinleo committed Sep 22, 2023
2 parents 2a971d8 + 67bed75 commit 48f3b79
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/Adapter/Reporter/KafkaClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
use Throwable;
use Zipkin\Reporters\Http\ClientFactory;

use function Hyperf\Support\msleep;

class KafkaClientFactory implements ClientFactory
{
protected ?Channel $chan = null;
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
});
Expand Down
7 changes: 6 additions & 1 deletion src/Aspect/CoroutineAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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'];
Expand All @@ -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()]);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Aspect/DbAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions src/Aspect/ElasticserachAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions src/Aspect/HttpClientAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Aspect/JsonRpcAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/Aspect/MethodAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions src/Aspect/RedisAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 6 additions & 3 deletions src/Aspect/TraceAnnotationAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,7 +26,7 @@ class TraceAnnotationAspect extends AbstractAspect
Trace::class,
];

public function __construct()
public function __construct(private SwitchManager $switchManager)
{
}

Expand All @@ -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();
Expand Down

0 comments on commit 48f3b79

Please sign in to comment.