Skip to content
2 changes: 1 addition & 1 deletion src/sentry/class_map/SentrySdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ public static function getCurrentHub(): HubInterface
*/
public static function setCurrentHub(HubInterface $hub): HubInterface
{
return tap($hub, fn ($hub) => Context::set(__CLASS__, $hub));
return Context::set(__CLASS__, $hub);
}
}
1 change: 1 addition & 0 deletions src/sentry/publish/sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
'crontab:run',
'gen:*',
'migrate*',
'sentry:test',
'tinker',
'vendor:publish',
],
Expand Down
7 changes: 3 additions & 4 deletions src/sentry/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ public function __invoke(): array
'dependencies' => [
\Sentry\ClientBuilder::class => Factory\ClientBuilderFactory::class,
\Sentry\State\HubInterface::class => Factory\HubFactory::class,
// \Sentry\HttpClient\HttpClientInterface::class => HttpClient\HttpClientFactory::class,
\Sentry\Transport\TransportInterface::class => Transport\CoHttpTransport::class,
],
'listeners' => [
Listener\EventHandleListener::class,
Crons\Listener\EventHandleListener::class,
Tracing\Listener\EventHandleListener::class,
Listener\EventHandleListener::class => PHP_INT_MAX - 1,
Crons\Listener\EventHandleListener::class => PHP_INT_MAX - 1,
Tracing\Listener\EventHandleListener::class => PHP_INT_MAX, // !! Make sure it is the first one to handle the event
],
'annotations' => [
'scan' => [
Expand Down
20 changes: 0 additions & 20 deletions src/sentry/src/Listener/EventHandleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Hyperf\Amqp\Event as AmqpEvent;
use Hyperf\AsyncQueue\Event as AsyncQueueEvent;
use Hyperf\Command\Event as CommandEvent;
use Hyperf\Context\Context;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Crontab\Event as CrontabEvent;
Expand Down Expand Up @@ -44,8 +43,6 @@
*/
class EventHandleListener implements ListenerInterface
{
public const HUB = 'sentry.context.hub';

protected array $missingKeys = [
// Enable
'sentry.enable.amqp',
Expand Down Expand Up @@ -207,11 +204,6 @@ protected function captureException(?Throwable $throwable): void
}
}

protected function setupSentrySdk(): void
{
Context::getOrSet(static::HUB, fn () => SentrySdk::init());
}

protected function flushEvents(): void
{
try {
Expand Down Expand Up @@ -356,8 +348,6 @@ protected function handleRequestReceived(object $event): void
if (! $this->feature->isEnabled('request')) {
return;
}

$this->setupSentrySdk();
}

/**
Expand All @@ -382,8 +372,6 @@ protected function handleCommandStarting(object $event): void
return;
}

$this->setupSentrySdk();

Integration::configureScope(static function (Scope $scope) use ($event): void {
$scope->setTag('command', $event->getCommand()->getName());
});
Expand Down Expand Up @@ -456,8 +444,6 @@ protected function handleAsyncQueueJobProcessing(object $event): void
return;
}

$this->setupSentrySdk();

if ($this->feature->isBreadcrumbEnabled('async_queue')) {
$job = [
'job' => $event->getMessage()->job()::class,
Expand Down Expand Up @@ -507,8 +493,6 @@ protected function handleCrontabTaskStarting(object $event): void
if (! $this->feature->isEnabled('crontab')) {
return;
}

$this->setupSentrySdk();
}

/**
Expand Down Expand Up @@ -544,8 +528,6 @@ protected function handleAmqpMessageProcessing(object $event): void
if (! $this->feature->isEnabled('amqp')) {
return;
}

$this->setupSentrySdk();
}

/**
Expand Down Expand Up @@ -581,8 +563,6 @@ protected function handleKafkaMessageProcessing(object $event): void
if (! $this->feature->isEnabled('kafka')) {
return;
}

$this->setupSentrySdk();
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/sentry/src/Tracing/Tracer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ public function __construct(protected Feature $feature)
*/
public function startTransaction(TransactionContext $transactionContext, array $customSamplingContext = []): Transaction
{
$hub = SentrySdk::init();
$hub = SentrySdk::getCurrentHub();
$hub->pushScope();
$hub->configureScope(static fn (Scope $scope) => $scope->clearBreadcrumbs());

defer(static fn () => $hub->popScope());

$transactionContext->setData(['coroutine.id' => Coroutine::id()] + $transactionContext->getData());

Expand Down