-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Deeka Wong <[email protected]>
- Loading branch information
1 parent
6558ae6
commit 595c944
Showing
3 changed files
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
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,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of friendsofhyperf/components. | ||
* | ||
* @link https://github.com/friendsofhyperf/components | ||
* @document https://github.com/friendsofhyperf/components/blob/main/README.md | ||
* @contact [email protected] | ||
*/ | ||
|
||
namespace FriendsOfHyperf\Sentry\Aspect; | ||
|
||
use FriendsOfHyperf\Sentry\Integration; | ||
use FriendsOfHyperf\Sentry\Switcher; | ||
use Hyperf\Di\Aop\AbstractAspect; | ||
use Hyperf\Di\Aop\ProceedingJoinPoint; | ||
use Sentry\Breadcrumb; | ||
|
||
use function Hyperf\Tappable\tap; | ||
|
||
class CacheAspect extends AbstractAspect | ||
{ | ||
public array $classes = [ | ||
'Hyperf\Cache\Driver\*Driver::fetch', | ||
'Hyperf\Cache\Driver\*Driver::get', | ||
'Hyperf\Cache\Driver\*Driver::getMultiple', | ||
'Hyperf\Cache\Driver\*Driver::set', | ||
'Hyperf\Cache\Driver\*Driver::setMultiple', | ||
'Hyperf\Cache\Driver\*Driver::delete', | ||
'Hyperf\Cache\Driver\*Driver::deleteMultiple', | ||
]; | ||
|
||
public function __construct(protected Switcher $switcher) | ||
{ | ||
} | ||
|
||
public function process(ProceedingJoinPoint $proceedingJoinPoint) | ||
{ | ||
$startTime = microtime(true); | ||
|
||
return tap($proceedingJoinPoint->process(), function ($result) use ($proceedingJoinPoint, $startTime) { | ||
if (! $this->switcher->isBreadcrumbEnable('cache')) { | ||
return; | ||
} | ||
$arguments = $proceedingJoinPoint->arguments['keys']; | ||
$method = sprintf('%s::%s()', $proceedingJoinPoint->className, $proceedingJoinPoint->methodName); | ||
|
||
$data['result'] = $result; | ||
$data['arguments'] = $arguments; | ||
$data['timeMs'] = (microtime(true) - $startTime) * 1000; | ||
|
||
Integration::addBreadcrumb(new Breadcrumb( | ||
Breadcrumb::LEVEL_INFO, | ||
Breadcrumb::TYPE_DEFAULT, | ||
'cache', | ||
$method, | ||
$data | ||
)); | ||
}); | ||
} | ||
} |
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