Skip to content

Commit

Permalink
Merge branch 'master' into 3.0-merge
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/test.yml
#	src/di/src/Annotation/Scanner.php
#	src/di/tests/InjectTest.php
  • Loading branch information
limingxinleo committed Jan 17, 2022
2 parents 89b8a34 + 272b58b commit 0aca810
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/Aspect/ElasticserachAspect.php
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;
}
}

0 comments on commit 0aca810

Please sign in to comment.