-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into 3.0-merge
# Conflicts: # .github/workflows/test.yml # src/di/src/Annotation/Scanner.php # src/di/tests/InjectTest.php
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of Hyperf. | ||
* | ||
* @link https://www.hyperf.io | ||
* @document https://hyperf.wiki | ||
* @contact [email protected] | ||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE | ||
*/ | ||
namespace Hyperf\Tracer\Aspect; | ||
|
||
use Elasticsearch\Client; | ||
use Hyperf\Di\Aop\AbstractAspect; | ||
use Hyperf\Di\Aop\ProceedingJoinPoint; | ||
use Hyperf\Tracer\SpanStarter; | ||
use Hyperf\Tracer\SpanTagManager; | ||
use Hyperf\Tracer\SwitchManager; | ||
use OpenTracing\Tracer; | ||
|
||
class ElasticserachAspect extends AbstractAspect | ||
{ | ||
use SpanStarter; | ||
|
||
public array $classes = [ | ||
Client::class . '::bulk', | ||
Client::class . '::count', | ||
Client::class . '::create', | ||
Client::class . '::get', | ||
Client::class . '::getSource', | ||
Client::class . '::index', | ||
Client::class . '::mget', | ||
Client::class . '::msearch', | ||
Client::class . '::scroll', | ||
Client::class . '::search', | ||
Client::class . '::update', | ||
Client::class . '::updateByQuery', | ||
Client::class . '::search', | ||
]; | ||
|
||
public function __construct(private Tracer $tracer, private SwitchManager $switchManager, private SpanTagManager $spanTagManager) | ||
{ | ||
} | ||
|
||
/** | ||
* @return mixed return the value from process method of ProceedingJoinPoint, or the value that you handled | ||
*/ | ||
public function process(ProceedingJoinPoint $proceedingJoinPoint) | ||
{ | ||
$key = $proceedingJoinPoint->className . '::' . $proceedingJoinPoint->methodName; | ||
$span = $this->startSpan($key); | ||
try { | ||
$result = $proceedingJoinPoint->process(); | ||
} catch (\Throwable $e) { | ||
$span->setTag('error', true); | ||
$span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]); | ||
throw $e; | ||
} finally { | ||
$span->finish(); | ||
} | ||
return $result; | ||
} | ||
} |