From 272b58b1a7738b4c751a3ff651bad12ae8afb64a Mon Sep 17 00:00:00 2001 From: Rock <35133768+Rock-liyi@users.noreply.github.com> Date: Fri, 14 Jan 2022 18:21:28 +0800 Subject: [PATCH] Added `Hyperf\Tracer\Aspect\ElasticserachAspect` which used to record traces for elasticsearch. (#4453) --- src/Aspect/ElasticserachAspect.php | 85 ++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/Aspect/ElasticserachAspect.php diff --git a/src/Aspect/ElasticserachAspect.php b/src/Aspect/ElasticserachAspect.php new file mode 100644 index 0000000..dc7d3ef --- /dev/null +++ b/src/Aspect/ElasticserachAspect.php @@ -0,0 +1,85 @@ +tracer = $tracer; + $this->switchManager = $switchManager; + $this->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; + } +}