diff --git a/src/sentry/src/Tracing/Aspect/ElasticsearchAspect.php b/src/sentry/src/Tracing/Aspect/ElasticsearchAspect.php index 802bab758..d36cf26ad 100644 --- a/src/sentry/src/Tracing/Aspect/ElasticsearchAspect.php +++ b/src/sentry/src/Tracing/Aspect/ElasticsearchAspect.php @@ -66,13 +66,7 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) op: 'db.elasticsearch', description: sprintf('%s::%s()', $proceedingJoinPoint->className, $proceedingJoinPoint->methodName), origin: 'auto.elasticsearch', - ); - - if (! $span) { - return $proceedingJoinPoint->process(); - } - - $span->setData([ + )?->setData([ 'coroutine.id' => Coroutine::id(), 'db.system' => 'elasticsearch', 'db.operation.name' => $proceedingJoinPoint->methodName, @@ -86,12 +80,12 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) try { $result = $proceedingJoinPoint->process(); if ($this->switcher->isTracingExtraTagEnabled('elasticsearch.result')) { - $span->setData([ + $span?->setData([ 'elasticsearch.result' => json_encode($result, JSON_UNESCAPED_UNICODE), ]); } } catch (Throwable $exception) { - $span->setStatus(SpanStatus::internalError()) + $span?->setStatus(SpanStatus::internalError()) ->setTags([ 'error' => 'true', 'exception.class' => $exception::class, @@ -99,14 +93,14 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) 'exception.code' => (string) $exception->getCode(), ]); if ($this->switcher->isTracingExtraTagEnabled('exception.stack_trace')) { - $span->setData([ + $span?->setData([ 'exception.stack_trace' => (string) $exception, ]); } throw $exception; } finally { - $span->finish(); + $span?->finish(); } return $result; diff --git a/src/sentry/src/Tracing/Aspect/FilesystemAspect.php b/src/sentry/src/Tracing/Aspect/FilesystemAspect.php index 319c8c943..af1f673bd 100644 --- a/src/sentry/src/Tracing/Aspect/FilesystemAspect.php +++ b/src/sentry/src/Tracing/Aspect/FilesystemAspect.php @@ -12,14 +12,16 @@ namespace FriendsOfHyperf\Sentry\Tracing\Aspect; use FriendsOfHyperf\Sentry\Aspect\FilesystemAspect as BaseFilesystemAspect; +use FriendsOfHyperf\Sentry\Tracing\SpanStarter; use Hyperf\Di\Aop\ProceedingJoinPoint; use Override; -use Sentry\Tracing\SpanContext; - -use function Sentry\trace; +use Sentry\Tracing\SpanStatus; +use Throwable; class FilesystemAspect extends BaseFilesystemAspect { + use SpanStarter; + #[Override] public function process(ProceedingJoinPoint $proceedingJoinPoint) { @@ -29,13 +31,30 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) [$op, $description, $data] = $this->getSentryMetadata($proceedingJoinPoint); - return trace( - fn () => $proceedingJoinPoint->process(), - SpanContext::make() - ->setOp($op) - ->setData($data) - ->setOrigin('auto.filesystem') - ->setDescription($description) - ); + $span = $this->startSpan( + op: $op, + description: $description, + origin: 'auto.filesystem', + )?->setData($data); + + try { + return $proceedingJoinPoint->process(); + } catch (Throwable $exception) { + $span?->setStatus(SpanStatus::internalError()) + ->setTags([ + 'error' => 'true', + 'exception.class' => $exception::class, + 'exception.message' => $exception->getMessage(), + 'exception.code' => (string) $exception->getCode(), + ]); + if ($this->switcher->isTracingExtraTagEnabled('exception.stack_trace')) { + $span?->setData([ + 'exception.stack_trace' => (string) $exception, + ]); + } + throw $exception; + } finally { + $span?->finish(); + } } }