Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
457f497
refactor(sentry): improve span lifecycle management and code clarity
huangdijia Sep 20, 2025
8204c8d
feat(sentry): enhance database event handling with transaction suppor…
huangdijia Sep 20, 2025
92e052b
feat(sentry): add conditional handling for SQL bindings in DbAspect a…
huangdijia Sep 20, 2025
5a4c144
fix(sentry): correct data assignment for SQL bindings in DbAspect
huangdijia Sep 20, 2025
e059f40
fix(sentry): remove redundant line in SQL bindings data assignment in…
huangdijia Sep 20, 2025
9faeb94
fix(sentry): improve conditional checks and data assignment in tracin…
huangdijia Sep 20, 2025
1e53c41
fix(sentry): inject additional trace context headers in GuzzleHttpCli…
huangdijia Sep 20, 2025
8955190
fix(sentry): rename span name for batch sending in KafkaProducerAspect
huangdijia Sep 20, 2025
1f6ff3d
fix(sentry): simplify span result handling in RedisAspect
huangdijia Sep 20, 2025
e57e286
fix(sentry): ensure result is returned in RpcAspect processing
huangdijia Sep 20, 2025
9ce7c5a
fix(sentry): enhance command event handling with breadcrumbs and scop…
huangdijia Sep 20, 2025
e4ff4bb
fix(sentry): add configuration options for breadcrumbs in async queue…
huangdijia Sep 20, 2025
98cb538
fix(sentry): improve header injection for distributed tracing in Grpc…
huangdijia Sep 20, 2025
8013f32
fix(sentry): ensure span is valid before injecting trace context in G…
huangdijia Sep 20, 2025
8d1b5bb
fix(sentry): enhance command breadcrumb logging with input and exit c…
huangdijia Sep 20, 2025
29f58b5
fix(sentry): add command input option for breadcrumbs configuration
huangdijia Sep 20, 2025
1d3f9e3
fix(switcher): rename breadcrumb enable methods for consistency and d…
huangdijia Sep 20, 2025
69ab129
fix(switcher): deprecate isExceptionIgnored method in favor of isExce…
huangdijia Sep 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/sentry/publish/sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@
],

'breadcrumbs' => [
'async_queue' => env('SENTRY_BREADCRUMBS_ASYNC_QUEUE', true),
'cache' => env('SENTRY_BREADCRUMBS_CACHE', true),
'command' => env('SENTRY_BREADCRUMBS_COMMAND', true),
'command_input' => env('SENTRY_BREADCRUMBS_COMMAND_INPUT', true),
'sql_queries' => env('SENTRY_BREADCRUMBS_SQL_QUERIES', true),
'sql_bindings' => env('SENTRY_BREADCRUMBS_SQL_BINDINGS', true),
'sql_transaction' => env('SENTRY_BREADCRUMBS_SQL_TRANSACTION', true),
Expand Down Expand Up @@ -113,6 +116,7 @@
'exception.stack_trace' => true,
'amqp.result' => false,
'annotation.result' => false,
'db.sql.bindings' => true,
'db.result' => false,
'elasticsearch.result' => false,
'http.response.body.contents' => false,
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/src/Aspect/CacheAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
$startTime = microtime(true);

return tap($proceedingJoinPoint->process(), function ($result) use ($proceedingJoinPoint, $startTime) {
if (! $this->switcher->isBreadcrumbEnable('cache')) {
if (! $this->switcher->isBreadcrumbEnabled('cache')) {
return;
}
$arguments = $proceedingJoinPoint->arguments['keys'];
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/src/Aspect/GuzzleHttpClientAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(protected Switcher $switcher)
public function process(ProceedingJoinPoint $proceedingJoinPoint)
{
// If the guzzle aspect is disabled, we will not record the request.
if (! $this->switcher->isBreadcrumbEnable('guzzle')) {
if (! $this->switcher->isBreadcrumbEnabled('guzzle')) {
return $proceedingJoinPoint->process();
}

Expand Down
2 changes: 1 addition & 1 deletion src/sentry/src/Aspect/LoggerAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(protected Switcher $switcher)
public function process(ProceedingJoinPoint $proceedingJoinPoint)
{
return tap($proceedingJoinPoint->process(), function ($result) use ($proceedingJoinPoint) {
if (! $this->switcher->isBreadcrumbEnable('logs')) {
if (! $this->switcher->isBreadcrumbEnabled('logs')) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/sentry/src/Aspect/RedisAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
return tap($proceedingJoinPoint->process(), function ($result) use ($arguments, $startTime) {
if (
class_exists(CommandExecuted::class)
|| ! $this->switcher->isBreadcrumbEnable('redis')
|| ! $this->switcher->isBreadcrumbEnabled('redis')
) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/src/Crons/Listener/EventHandleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function listen(): array
*/
public function process(object $event): void
{
if (! $this->switcher->isCronsEnable()) {
if (! $this->switcher->isCronsEnabled()) {
return;
}

Expand Down
138 changes: 104 additions & 34 deletions src/sentry/src/Listener/EventHandleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@
use Psr\Container\ContainerInterface;
use Sentry\Breadcrumb;
use Sentry\SentrySdk;
use Sentry\State\Scope;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputInterface;
use Throwable;

/**
* @property InputInterface $input
* @property int $exitCode
*/
class EventHandleListener implements ListenerInterface
{
public const HUB = 'sentry.context.hub';
Expand Down Expand Up @@ -156,7 +163,6 @@ public function process(object $event): void

// Command events
CommandEvent\BeforeHandle::class => $this->handleCommandStarting($event),
CommandEvent\FailToHandle::class => $this->handleCommandFailed($event),
CommandEvent\AfterExecute::class => $this->handleCommandFinished($event),

// Async Queue events
Expand Down Expand Up @@ -233,8 +239,8 @@ protected function setupRequestLifecycle(): void
}

if (
! $this->switcher->isEnable('request')
&& ! $this->switcher->isTracingEnable('request')
! $this->switcher->isEnabled('request')
&& ! $this->switcher->isTracingEnabled('request')
) {
return;
}
Expand Down Expand Up @@ -277,7 +283,7 @@ protected function setupRedisEventEnable(): void
*/
protected function handleDbQueryExecuted(object $event): void
{
if (! $this->switcher->isBreadcrumbEnable('sql_queries')) {
if (! $this->switcher->isBreadcrumbEnabled('sql_queries')) {
return;
}

Expand All @@ -287,7 +293,7 @@ protected function handleDbQueryExecuted(object $event): void
$data['executionTimeMs'] = $event->time;
}

if ($this->switcher->isBreadcrumbEnable('sql_bindings')) {
if ($this->switcher->isBreadcrumbEnabled('sql_bindings')) {
$data['bindings'] = $event->bindings;
}

Expand All @@ -305,7 +311,7 @@ protected function handleDbQueryExecuted(object $event): void
*/
protected function handleDbTransaction(object $event): void
{
if (! $this->switcher->isBreadcrumbEnable('sql_transaction')) {
if (! $this->switcher->isBreadcrumbEnabled('sql_transaction')) {
return;
}

Expand All @@ -325,7 +331,7 @@ protected function handleDbTransaction(object $event): void
*/
protected function handleRedisCommandExecuted(object $event): void
{
if (! $this->switcher->isBreadcrumbEnable('redis')) {
if (! $this->switcher->isBreadcrumbEnabled('redis')) {
return;
}

Expand All @@ -347,7 +353,7 @@ protected function handleRedisCommandExecuted(object $event): void
*/
protected function handleRequestReceived(object $event): void
{
if (! $this->switcher->isEnable('request')) {
if (! $this->switcher->isEnabled('request')) {
return;
}

Expand All @@ -359,7 +365,7 @@ protected function handleRequestReceived(object $event): void
*/
protected function handleRequestTerminated(object $event): void
{
if (! $this->switcher->isEnable('request')) {
if (! $this->switcher->isEnabled('request')) {
return;
}

Expand All @@ -372,56 +378,108 @@ protected function handleRequestTerminated(object $event): void
*/
protected function handleCommandStarting(object $event): void
{
if (! $this->switcher->isEnable('command')) {
if (! $this->switcher->isEnabled('command')) {
return;
}

$this->setupSentrySdk();
}

/**
* @param CommandEvent\FailToHandle $event
*/
protected function handleCommandFailed(object $event): void
{
if (! $this->switcher->isEnable('command')) {
return;
}
Integration::configureScope(static function (Scope $scope) use ($event): void {
$scope->setTag('command', $event->getCommand()->getName());
});

$this->captureException($event->getThrowable());
$this->flushEvents();
if ($this->switcher->isBreadcrumbEnabled('command')) {
$data = [];
if ($this->switcher->isBreadcrumbEnabled('command_input')) {
/** @var InputInterface $input */
$input = (fn () => $this->input)->call($event->getCommand());
$data['input'] = $this->extractConsoleCommandInput($input);
}

Integration::addBreadcrumb(new Breadcrumb(
Breadcrumb::LEVEL_INFO,
Breadcrumb::TYPE_DEFAULT,
'command',
'Starting command: ' . $event->getCommand()->getName(),
$data
));
}
}

/**
* @param CommandEvent\AfterExecute $event
*/
protected function handleCommandFinished(object $event): void
{
if (! $this->switcher->isEnable('command')) {
if (! $this->switcher->isEnabled('command')) {
return;
}

if ($this->switcher->isBreadcrumbEnabled('command')) {
/** @var InputInterface $input */
/** @var int $exitCode */
[$input, $exitCode] = (function () {
return [
$this->input,
$this->exitCode,
];
})->call($event->getCommand());
$data = ['exit' => $exitCode];

if ($this->switcher->isBreadcrumbEnabled('command_input')) {
$data['input'] = $this->extractConsoleCommandInput($input);
}

Integration::addBreadcrumb(new Breadcrumb(
Breadcrumb::LEVEL_INFO,
Breadcrumb::TYPE_DEFAULT,
'command',
'Finished command: ' . $event->getCommand()->getName(),
$data
));
}

$this->captureException($event->getThrowable());
$this->flushEvents();

Integration::configureScope(static function (Scope $scope): void {
$scope->removeTag('command');
});
}

/**
* @param AsyncQueueEvent\BeforeHandle $event
*/
protected function handleAsyncQueueJobProcessing(object $event): void
{
if (! $this->switcher->isEnable('async_queue')) {
if (! $this->switcher->isEnabled('async_queue')) {
return;
}

$this->setupSentrySdk();

if ($this->switcher->isBreadcrumbEnabled('async_queue')) {
$job = [
'job' => $event->getMessage()->job()::class,
'attempts' => $event->getMessage()->getAttempts(),
];

Integration::addBreadcrumb(new Breadcrumb(
Breadcrumb::LEVEL_INFO,
Breadcrumb::TYPE_DEFAULT,
'queue.job',
'Processing async_queue job',
$job
));
}
}

/**
* @param AsyncQueueEvent\AfterHandle $event
*/
protected function handleAsyncQueueJobProcessed(object $event): void
{
if (! $this->switcher->isEnable('async_queue')) {
if (! $this->switcher->isEnabled('async_queue')) {
return;
}

Expand All @@ -433,7 +491,7 @@ protected function handleAsyncQueueJobProcessed(object $event): void
*/
protected function handleAsyncQueueJobRetryOrFailed(object $event): void
{
if (! $this->switcher->isEnable('async_queue')) {
if (! $this->switcher->isEnabled('async_queue')) {
return;
}

Expand All @@ -446,7 +504,7 @@ protected function handleAsyncQueueJobRetryOrFailed(object $event): void
*/
protected function handleCrontabTaskStarting(object $event): void
{
if (! $this->switcher->isEnable('crontab')) {
if (! $this->switcher->isEnabled('crontab')) {
return;
}

Expand All @@ -458,7 +516,7 @@ protected function handleCrontabTaskStarting(object $event): void
*/
protected function handleCrontabTaskFinished(object $event): void
{
if (! $this->switcher->isEnable('crontab')) {
if (! $this->switcher->isEnabled('crontab')) {
return;
}

Expand All @@ -470,7 +528,7 @@ protected function handleCrontabTaskFinished(object $event): void
*/
protected function handleCrontabTaskFailed(object $event): void
{
if (! $this->switcher->isEnable('crontab')) {
if (! $this->switcher->isEnabled('crontab')) {
return;
}

Expand All @@ -483,7 +541,7 @@ protected function handleCrontabTaskFailed(object $event): void
*/
protected function handleAmqpMessageProcessing(object $event): void
{
if (! $this->switcher->isEnable('amqp')) {
if (! $this->switcher->isEnabled('amqp')) {
return;
}

Expand All @@ -495,7 +553,7 @@ protected function handleAmqpMessageProcessing(object $event): void
*/
protected function handleAmqpMessageProcessed(object $event): void
{
if (! $this->switcher->isEnable('amqp')) {
if (! $this->switcher->isEnabled('amqp')) {
return;
}

Expand All @@ -507,7 +565,7 @@ protected function handleAmqpMessageProcessed(object $event): void
*/
protected function handleAmqpMessageFailed(object $event): void
{
if (! $this->switcher->isEnable('amqp')) {
if (! $this->switcher->isEnabled('amqp')) {
return;
}

Expand All @@ -520,7 +578,7 @@ protected function handleAmqpMessageFailed(object $event): void
*/
protected function handleKafkaMessageProcessing(object $event): void
{
if (! $this->switcher->isEnable('kafka')) {
if (! $this->switcher->isEnabled('kafka')) {
return;
}

Expand All @@ -532,7 +590,7 @@ protected function handleKafkaMessageProcessing(object $event): void
*/
protected function handleKafkaMessageProcessed(object $event): void
{
if (! $this->switcher->isEnable('kafka')) {
if (! $this->switcher->isEnabled('kafka')) {
return;
}

Expand All @@ -544,11 +602,23 @@ protected function handleKafkaMessageProcessed(object $event): void
*/
protected function handleKafkaMessageFailed(object $event): void
{
if (! $this->switcher->isEnable('kafka')) {
if (! $this->switcher->isEnabled('kafka')) {
return;
}

$this->captureException($event->getThrowable());
$this->flushEvents();
}

/**
* Extract the command input arguments if possible.
*/
private function extractConsoleCommandInput(?InputInterface $input): ?string
{
if ($input instanceof ArgvInput) {
return (string) $input;
}

return null;
}
}
Loading