Skip to content

Commit

Permalink
Copy context from parent coroutine (#391)
Browse files Browse the repository at this point in the history
Co-authored-by: Deeka Wong <[email protected]>
  • Loading branch information
huangdijia and huangdijia committed Oct 30, 2023
1 parent efb0dee commit 95b58c8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Aspect/CoroutineAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,25 @@
use Hyperf\Di\Aop\AbstractAspect;
use Hyperf\Di\Aop\ProceedingJoinPoint;
use Hyperf\Engine\Coroutine as Co;
use Sentry\SentrySdk;

class CoroutineAspect extends AbstractAspect
{
public array $classes = [
'Hyperf\Coroutine\Coroutine::create',
];

protected array $keys = [
\Sentry\SentrySdk::class,
\Psr\Http\Message\ServerRequestInterface::class,
];

public function process(ProceedingJoinPoint $proceedingJoinPoint)
{
$callable = $proceedingJoinPoint->arguments['keys']['callable'];
$keys = $this->keys;

$proceedingJoinPoint->arguments['keys']['callable'] = function () use ($callable) {
Context::copy(Co::pid(), [SentrySdk::class]);
$proceedingJoinPoint->arguments['keys']['callable'] = function () use ($callable, $keys) {
Context::copy(Co::pid(), $keys);
$callable();
};

Expand Down

0 comments on commit 95b58c8

Please sign in to comment.