-
-
Notifications
You must be signed in to change notification settings - Fork 27
refactor(sentry): remove redundant Integration::flushEvents() calls from defer callbacks #1054
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
refactor(sentry): remove redundant Integration::flushEvents() calls from defer callbacks #1054
Conversation
…rom defer callbacks This change removes redundant Integration::flushEvents() calls from multiple defer callbacks in EventHandleListener. The event flushing is already handled in the finally block of the handleCommandFinished method, making these calls unnecessary and potentially causing performance issues due to duplicate flushes. The redundant calls are removed from: - handleRequestReceived defer callback (HTTP/RPC request handling) - handleCrontabTaskStarting defer callback (Crontab task execution) - handleAmqpMessageProcessing defer callback (AMQP message processing) - handleKafkaMessageProcessing defer callback (Kafka message processing) - handleAsyncQueueJobProcessing defer callback (AsyncQueue job processing) This refactoring improves code clarity and ensures event flushing occurs only once per command execution cycle.
功能概览本次变更禁用了 Sentry 集成中的 SingletonAspect 配置,并从多个事件处理器的清理逻辑中移除了显式的事件刷新调用,改变了事务/跨度完成时的事件处理行为。 变更详情
预估代码审查工作量🎯 3 (中等复杂度) | ⏱️ ~20 分钟 相关 PR
建议审查人
诗歌
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
💤 Files with no reviewable changes (1)
🧰 Additional context used📓 Path-based instructions (6)**/*.php📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
src/**/src/**/*.php📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
src/*/src/ConfigProvider.php📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/src/ConfigProvider.php📄 CodeRabbit inference engine (CLAUDE.md)
Files:
src/*/src/**/*.php📄 CodeRabbit inference engine (CLAUDE.md)
Files:
src/**/*.php📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (3)📚 Learning: 2025-12-12T05:33:43.947ZApplied to files:
📚 Learning: 2025-12-12T05:33:43.947ZApplied to files:
📚 Learning: 2025-12-12T05:33:20.686ZApplied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (1)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 PHPStan (2.1.33)At least one path must be specified to analyse. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
||
| // Finish transaction | ||
| $transaction->finish(); | ||
|
|
||
| // Flush events | ||
| Integration::flushEvents(); | ||
| }); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Removing Integration::flushEvents() from defer callbacks causes Sentry events for HTTP, AMQP, Kafka, and other non-command contexts to be queued but never sent.
Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
The refactoring centralizes event flushing into handleCommandFinished, which only triggers on CommandEvent::AfterExecute. This incorrectly assumes all operations are console commands. For other operations like HTTP requests, AMQP/Kafka consumers, and crontab/async jobs, the defer callbacks finish the transaction, but CommandEvent::AfterExecute never fires. Consequently, the new centralized flushing mechanism is never invoked for these contexts, leading to Sentry tracing data being queued indefinitely and ultimately lost.
💡 Suggested Fix
Restore the Integration::flushEvents() calls within the defer() callbacks for each non-command event handler (HTTP, AMQP, Kafka, Crontab, AsyncQueue). This ensures that events are flushed correctly at the end of each respective operation's lifecycle, independent of the command event system.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: src/sentry/src/Tracing/Listener/EventHandleListener.php#L337-L342
Potential issue: The refactoring centralizes event flushing into
`handleCommandFinished`, which only triggers on `CommandEvent::AfterExecute`. This
incorrectly assumes all operations are console commands. For other operations like HTTP
requests, AMQP/Kafka consumers, and crontab/async jobs, the `defer` callbacks finish the
transaction, but `CommandEvent::AfterExecute` never fires. Consequently, the new
centralized flushing mechanism is never invoked for these contexts, leading to Sentry
tracing data being queued indefinitely and ultimately lost.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7923473
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR attempts to remove what the author believes are redundant Integration::flushEvents() calls from defer callbacks in the Sentry event handling listener. The premise is that event flushing is handled in the finally block of handleCommandFinished, making these calls unnecessary. However, this assumption is fundamentally flawed.
Key Changes:
- Removed
Integration::flushEvents()calls from 5 defer callbacks that handle different event types - The changes affect HTTP/RPC requests, crontab tasks, AMQP message processing, Kafka message processing, and async queue job processing
| SentrySdk::getCurrentHub()->setSpan($transaction); | ||
|
|
||
| // Finish transaction | ||
| $transaction->finish(); |
Copilot
AI
Dec 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The removal of Integration::flushEvents() from this defer callback is incorrect. This defer callback handles Kafka message processing lifecycles, which are completely separate from command execution lifecycles. The Integration::flushEvents() in handleCommandFinished's finally block (line 457) only executes for CommandEvent\AfterExecute events (CLI commands), not for Kafka message consumption.
Without this flush call, Sentry events generated during Kafka message processing will not be sent to Sentry, resulting in data loss. The flush call must be restored here.
| $transaction->finish(); | |
| $transaction->finish(); | |
| // Flush Sentry events generated during Kafka message processing | |
| Integration::flushEvents(); |
| SentrySdk::getCurrentHub()->setSpan($transaction); | ||
|
|
||
| // Finish transaction | ||
| $transaction->finish(); |
Copilot
AI
Dec 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The removal of Integration::flushEvents() from this defer callback is incorrect. This defer callback handles async queue job processing lifecycles, which are completely separate from command execution lifecycles. The Integration::flushEvents() in handleCommandFinished's finally block (line 457) only executes for CommandEvent\AfterExecute events (CLI commands), not for async queue job processing.
Without this flush call, Sentry events generated during async queue job processing will not be sent to Sentry, resulting in data loss. The flush call must be restored here.
| $transaction->finish(); | |
| $transaction->finish(); | |
| // Flush Sentry events generated during async queue job processing | |
| Integration::flushEvents(); |
| SentrySdk::getCurrentHub()->setSpan($transaction); | ||
|
|
||
| // Finish transaction | ||
| $transaction->finish(); |
Copilot
AI
Dec 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The removal of Integration::flushEvents() from this defer callback is incorrect. This defer callback handles HTTP and RPC request lifecycles, which are completely separate from command execution lifecycles. The Integration::flushEvents() in handleCommandFinished's finally block (line 457) only executes for CommandEvent\AfterExecute events (CLI commands), not for HTTP/RPC requests.
Without this flush call, Sentry events generated during HTTP/RPC request handling will not be sent to Sentry, resulting in data loss. The flush call must be restored here.
| $transaction->finish(); | |
| $transaction->finish(); | |
| // Flush Sentry events for this HTTP/RPC request lifecycle | |
| Integration::flushEvents(); |
| SentrySdk::getCurrentHub()->setSpan($transaction); | ||
|
|
||
| // Finish transaction | ||
| $transaction->finish(); |
Copilot
AI
Dec 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The removal of Integration::flushEvents() from this defer callback is incorrect. This defer callback handles crontab task lifecycles, which are completely separate from command execution lifecycles. The Integration::flushEvents() in handleCommandFinished's finally block (line 457) only executes for CommandEvent\AfterExecute events (CLI commands), not for crontab tasks.
Without this flush call, Sentry events generated during crontab task execution will not be sent to Sentry, resulting in data loss. The flush call must be restored here.
| $transaction->finish(); | |
| $transaction->finish(); | |
| // Flush Sentry events generated during crontab task execution | |
| Integration::flushEvents(); |
| SentrySdk::getCurrentHub()->setSpan($transaction); | ||
|
|
||
| // Finish transaction | ||
| $transaction->finish(); |
Copilot
AI
Dec 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The removal of Integration::flushEvents() from this defer callback is incorrect. This defer callback handles AMQP message processing lifecycles, which are completely separate from command execution lifecycles. The Integration::flushEvents() in handleCommandFinished's finally block (line 457) only executes for CommandEvent\AfterExecute events (CLI commands), not for AMQP message consumption.
Without this flush call, Sentry events generated during AMQP message processing will not be sent to Sentry, resulting in data loss. The flush call must be restored here.
| $transaction->finish(); | |
| $transaction->finish(); | |
| // Flush Sentry events generated during AMQP message processing | |
| Integration::flushEvents(); |
…rom defer callbacks (#1054) * refactor(sentry): remove redundant Integration::flushEvents() calls from defer callbacks This change removes redundant Integration::flushEvents() calls from multiple defer callbacks in EventHandleListener. The event flushing is already handled in the finally block of the handleCommandFinished method, making these calls unnecessary and potentially causing performance issues due to duplicate flushes. The redundant calls are removed from: - handleRequestReceived defer callback (HTTP/RPC request handling) - handleCrontabTaskStarting defer callback (Crontab task execution) - handleAmqpMessageProcessing defer callback (AMQP message processing) - handleKafkaMessageProcessing defer callback (Kafka message processing) - handleAsyncQueueJobProcessing defer callback (AsyncQueue job processing) This refactoring improves code clarity and ensures event flushing occurs only once per command execution cycle. * chore: disable Sentry SingletonAspect registration --------- Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
Summary
Integration::flushEvents()calls from multipledefer()callbacks inEventHandleListenerfinallyblock ofhandleCommandFinished, making these calls unnecessaryChanges
The redundant
Integration::flushEvents()calls were removed from the following defer callbacks:handleRequestReceived- HTTP/RPC request handlinghandleCrontabTaskStarting- Crontab task executionhandleAmqpMessageProcessing- AMQP message processinghandleKafkaMessageProcessing- Kafka message processinghandleAsyncQueueJobProcessing- AsyncQueue job processingContext
This is a follow-up refactoring to commit
32062ab6which moved event flushing to thefinallyblock inEventHandleListener. The removal of these redundant calls ensures event flushing occurs only once per command execution cycle.Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.