mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Added switch for ElasticserachAspect
and CoroutineAspect
. (#6200)
This commit is contained in:
parent
9531b1d41c
commit
16b1c82a17
@ -5,6 +5,7 @@
|
||||
- [#6188](https://github.com/hyperf/hyperf/pull/6188) Added Redis options name to support string type.
|
||||
- [#6193](https://github.com/hyperf/hyperf/pull/6193) Support http and websocket protocols at the same port for swow server.
|
||||
- [#6198](https://github.com/hyperf/hyperf/pull/6198) Added `RpcAspect` and use it instead of `JsonRpcAspect`.
|
||||
- [#6200](https://github.com/hyperf/hyperf/pull/6200) Added switch for `ElasticserachAspect` and `CoroutineAspect`.
|
||||
|
||||
# v3.0.38 - 2023-10-05
|
||||
|
||||
|
@ -16,7 +16,9 @@ use function Hyperf\Support\env;
|
||||
return [
|
||||
'default' => env('TRACER_DRIVER', 'zipkin'),
|
||||
'enable' => [
|
||||
'coroutine' => env('TRACER_ENABLE_COROUTINE', false),
|
||||
'db' => env('TRACER_ENABLE_DB', false),
|
||||
'elasticserach' => env('TRACER_ENABLE_ELASTICSERACH', false),
|
||||
'exception' => env('TRACER_ENABLE_EXCEPTION', false),
|
||||
'guzzle' => env('TRACER_ENABLE_GUZZLE', false),
|
||||
'method' => env('TRACER_ENABLE_METHOD', false),
|
||||
|
@ -14,6 +14,7 @@ namespace Hyperf\Tracer\Aspect;
|
||||
use Hyperf\Di\Aop\AbstractAspect;
|
||||
use Hyperf\Di\Aop\ProceedingJoinPoint;
|
||||
use Hyperf\Engine\Coroutine as Co;
|
||||
use Hyperf\Tracer\SpanTagManager;
|
||||
use Hyperf\Tracer\SwitchManager;
|
||||
use Hyperf\Tracer\TracerContext;
|
||||
use OpenTracing\Span;
|
||||
@ -25,12 +26,16 @@ class CoroutineAspect extends AbstractAspect
|
||||
'Hyperf\Coroutine\Coroutine::create',
|
||||
];
|
||||
|
||||
public function __construct(private SwitchManager $switchManager)
|
||||
public function __construct(protected SwitchManager $switchManager, protected SpanTagManager $spanTagManager)
|
||||
{
|
||||
}
|
||||
|
||||
public function process(ProceedingJoinPoint $proceedingJoinPoint)
|
||||
{
|
||||
if (! $this->switchManager->isEnable('coroutine')) {
|
||||
return $proceedingJoinPoint->process();
|
||||
}
|
||||
|
||||
$callable = $proceedingJoinPoint->arguments['keys']['callable'];
|
||||
$root = TracerContext::getRoot();
|
||||
|
||||
@ -41,7 +46,9 @@ class CoroutineAspect extends AbstractAspect
|
||||
$child = $tracer->startSpan('coroutine', [
|
||||
'child_of' => $root->getContext(),
|
||||
]);
|
||||
$child->setTag('coroutine.id', Co::id());
|
||||
if ($this->spanTagManager->has('coroutine', 'id')) {
|
||||
$child->setTag($this->spanTagManager->get('coroutine', 'id'), Co::id());
|
||||
}
|
||||
TracerContext::setRoot($child);
|
||||
Co::defer(function () use ($child, $tracer) {
|
||||
$child->finish();
|
||||
|
@ -48,6 +48,10 @@ class ElasticserachAspect extends AbstractAspect
|
||||
*/
|
||||
public function process(ProceedingJoinPoint $proceedingJoinPoint)
|
||||
{
|
||||
if ($this->switchManager->isEnable('elasticserach') === false) {
|
||||
return $proceedingJoinPoint->process();
|
||||
}
|
||||
|
||||
$key = $proceedingJoinPoint->className . '::' . $proceedingJoinPoint->methodName;
|
||||
$span = $this->startSpan($key);
|
||||
try {
|
||||
|
@ -12,7 +12,9 @@ declare(strict_types=1);
|
||||
namespace Hyperf\Tracer;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Hyperf\Tracer\Aspect\CoroutineAspect;
|
||||
use Hyperf\Tracer\Aspect\CreateTraceContextAspect;
|
||||
use Hyperf\Tracer\Aspect\ElasticserachAspect;
|
||||
use Hyperf\Tracer\Aspect\HttpClientAspect;
|
||||
use Hyperf\Tracer\Aspect\RedisAspect;
|
||||
use Hyperf\Tracer\Aspect\RpcAspect;
|
||||
@ -47,7 +49,9 @@ class ConfigProvider
|
||||
],
|
||||
],
|
||||
'aspects' => [
|
||||
CoroutineAspect::class,
|
||||
CreateTraceContextAspect::class,
|
||||
ElasticserachAspect::class,
|
||||
HttpClientAspect::class,
|
||||
RedisAspect::class,
|
||||
RpcAspect::class,
|
||||
|
Loading…
Reference in New Issue
Block a user