-
-
Notifications
You must be signed in to change notification settings - Fork 28
feat(sentry): add SentrySdkAspect for coroutine-safe SDK usage #1063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6cce8a1
78999fb
8d0c644
5f543e6
35252e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| <?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 huangdijia@gmail.com | ||
| */ | ||
|
|
||
| namespace FriendsOfHyperf\Sentry\Aspect; | ||
|
|
||
| use Closure; | ||
| use Hyperf\Context\Context; | ||
| use Hyperf\Di\Aop\AbstractAspect; | ||
| use Hyperf\Di\Aop\ProceedingJoinPoint; | ||
| use Sentry\SentrySdk; | ||
| use Sentry\State\HubInterface; | ||
| use Sentry\State\RuntimeContextManager; | ||
|
|
||
| use function Hyperf\Support\make; | ||
|
|
||
| class SentrySdkAspect extends AbstractAspect | ||
| { | ||
| public array $classes = [ | ||
| SentrySdk::class . '::init', | ||
| SentrySdk::class . '::setCurrentHub', | ||
| SentrySdk::class . '::getRuntimeContextManager', | ||
| ]; | ||
|
|
||
| public function process(ProceedingJoinPoint $proceedingJoinPoint) | ||
| { | ||
| return match ($proceedingJoinPoint->methodName) { | ||
| 'init' => $this->handleInit($proceedingJoinPoint), | ||
| 'setCurrentHub' => $this->handleSetCurrentHub($proceedingJoinPoint), | ||
| 'getRuntimeContextManager' => $this->handleGetRuntimeContextManager($proceedingJoinPoint), | ||
| default => $proceedingJoinPoint->process(), | ||
| }; | ||
| } | ||
|
|
||
| private function handleInit(ProceedingJoinPoint $proceedingJoinPoint) | ||
| { | ||
| Context::set( | ||
| RuntimeContextManager::class, | ||
| new RuntimeContextManager(make(HubInterface::class)) | ||
| ); | ||
|
|
||
| return SentrySdk::getCurrentHub(); | ||
huangdijia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private function handleSetCurrentHub(ProceedingJoinPoint $proceedingJoinPoint) | ||
| { | ||
| $arguments = $proceedingJoinPoint->arguments['keys'] ?? []; | ||
| $hub = $arguments['hub']; | ||
huangdijia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // @phpstan-ignore-next-line | ||
| Closure::bind(fn () => static::getRuntimeContextManager()->setCurrentHub($hub), null, SentrySdk::class)(); | ||
|
|
||
| return $hub; | ||
| } | ||
huangdijia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private function handleGetRuntimeContextManager(ProceedingJoinPoint $proceedingJoinPoint) | ||
| { | ||
| return Context::getOrSet( | ||
| RuntimeContextManager::class, | ||
| fn () => new RuntimeContextManager(make(HubInterface::class)) | ||
| ); | ||
| } | ||
huangdijia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
huangdijia marked this conversation as resolved.
Show resolved
Hide resolved
huangdijia marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
24
to
69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 补齐协程并发隔离测试,当前改动缺少回归保护。 该文件改动直接接管 我可以直接给你补一版 Pest 用例草稿(含并发场景和跨请求隔离断言),要我顺手起一个测试任务吗? 🧰 Tools🪛 PHPMD (2.15.0)[warning] 43-43: Avoid unused parameters such as '$proceedingJoinPoint'. (undefined) (UnusedFormalParameter) [warning] 63-63: Avoid unused parameters such as '$proceedingJoinPoint'. (undefined) (UnusedFormalParameter) |
||
Uh oh!
There was an error while loading. Please reload this page.