-
-
Notifications
You must be signed in to change notification settings - Fork 27
feat(sentry): add database connection pool metrics to breadcrumbs #960
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
Conversation
Add connection pool statistics (max connections, waiting connections, and current connections in use) to Sentry breadcrumbs for database events. This provides better visibility into database connection pool usage when debugging issues.
Walkthrough为 DbEvent\QueryExecuted 与 Redis 命令面包屑增强池统计:在监听器中通过 Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant App as 应用
participant Listener as EventHandleListener
participant DbPoolFactory as DbPoolFactory
participant DbPool as DB 连接池
participant RedisPoolFactory as RedisPoolFactory
participant RedisPool as Redis 连接池
participant Sentry as Sentry
App->>Listener: 触发 DbEvent\QueryExecuted / RedisCommandExecuted
rect rgb(245,250,255)
note right of Listener: 尝试收集对应池的统计并加入 breadcrumb
alt 处理 DB 事件
Listener->>DbPoolFactory: 获取 DB 池
DbPoolFactory-->>Listener: 返回 Pool 或 抛出异常
alt 成功
Listener->>DbPool: 读取 max/waiting/in-use
DbPool-->>Listener: 池统计
Listener->>Listener: 将统计加入 DB breadcrumb
else 异常
Listener->>Sentry: captureException(e)
end
end
alt 处理 Redis 事件
Listener->>RedisPoolFactory: 获取 Redis 池
RedisPoolFactory-->>Listener: 返回 Pool 或 抛出异常
alt 成功
Listener->>RedisPool: 读取 max/waiting/in-use
RedisPool-->>Listener: 池统计
Listener->>Listener: 将统计数组加入 Redis breadcrumb
else 异常
Listener->>Sentry: captureException(e)
end
end
end
Listener-->>App: 继续处理(面包屑包含或不包含池统计)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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). (12)
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.31)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 |
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.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/sentry/src/Listener/EventHandleListener.php(3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/*/src/**/*.php
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
All component PHP code must use the namespace pattern FriendsOfHyperf{ComponentName}
Files:
src/sentry/src/Listener/EventHandleListener.php
**/*.php
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.php: Code style must follow PSR-12 and be formatted by PHP-CS-Fixer per .php-cs-fixer.php
Run PHPStan and keep the codebase passing per phpstan.neon.dist
Files:
src/sentry/src/Listener/EventHandleListener.php
⏰ 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). (12)
- GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
- GitHub Check: Test on PHP 8.2 with Swoole 5.1.7
- GitHub Check: Test on PHP 8.2 with Swoole 6.0.2
- GitHub Check: Test on PHP 8.1 with Swoole 5.1.7
- GitHub Check: Test on PHP 8.3 with Swoole 5.1.7
- GitHub Check: Test on PHP 8.3 with Swoole 6.0.2
- GitHub Check: Test on PHP 8.1 with Swoole 5.1.7
- GitHub Check: Test on PHP 8.2 with Swoole 6.0.2
- GitHub Check: Test on PHP 8.2 with Swoole 5.1.7
- GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
- GitHub Check: Test on PHP 8.3 with Swoole 5.1.7
- GitHub Check: Test on PHP 8.3 with Swoole 6.0.2
🔇 Additional comments (2)
src/sentry/src/Listener/EventHandleListener.php (2)
23-23: 导入语句正确导入
PoolFactory和captureException函数的语句是必要的,格式正确。Also applies to: 41-41
287-292: 验证连接池方法可用性请确认
getPool($event->connectionName)返回的 Hyperf 连接池实例中包含并正确实现以下方法:
getOption()->getMaxConnections()getConnectionsInChannel()getCurrentConnections()如果这些方法定义在
vendor/hyperf/db-connection/src/**,请检查对应类并确保其行为符合预期。
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.
Actionable comments posted: 3
♻️ Duplicate comments (1)
src/sentry/src/Listener/EventHandleListener.php (1)
292-294: 一致化异常上报的处理方式:已修复,赞这里改为调用 $this->captureException($e) 与类内策略保持一致,解决了此前评审指出的不一致问题。
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/sentry/src/Listener/EventHandleListener.php(3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/*/src/**/*.php
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
All component PHP code must use the namespace pattern FriendsOfHyperf{ComponentName}
Files:
src/sentry/src/Listener/EventHandleListener.php
**/*.php
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.php: Code style must follow PSR-12 and be formatted by PHP-CS-Fixer per .php-cs-fixer.php
Run PHPStan and keep the codebase passing per phpstan.neon.dist
Files:
src/sentry/src/Listener/EventHandleListener.php
🔇 Additional comments (2)
src/sentry/src/Listener/EventHandleListener.php (2)
23-23: LGTM:新增 DB PoolFactory 引用合理用于采集连接池指标,搭配后续 try-catch 使用无问题。
30-30: LGTM:新增 Redis PoolFactory 引用合理用于采集 Redis 连接池指标,后续代码已做异常保护。
* feat(sentry): add database connection pool metrics to breadcrumbs Add connection pool statistics (max connections, waiting connections, and current connections in use) to Sentry breadcrumbs for database events. This provides better visibility into database connection pool usage when debugging issues. * feat(sentry): update breadcrumb type for Guzzle HTTP requests * refactor(EventHandleListener): replace direct captureException call with method reference * feat(redis): enhance Redis command breadcrumb with connection pool metrics * fix(EventHandleListener): correct PoolFactory alias for database connection pool --------- Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
Summary
Details
This change enhances the Sentry integration by adding database connection pool metrics to breadcrumbs when database events occur. The following metrics are now included:
max: Maximum number of connections in the poolwaiting: Number of connections waiting in the channeluse: Number of connections currently in useThe pool information retrieval is wrapped in a try-catch block to ensure that any errors during metrics collection are captured by Sentry without breaking the breadcrumb creation process.
Test plan
Summary by CodeRabbit
新功能
稳定性修复