-
-
Notifications
You must be signed in to change notification settings - Fork 27
fix: improve database read/write connection tracing #1025
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 TRACE_DB_USE_READ_PDO constant to track read PDO usage - Enhance DbConnectionAspect to detect getPdoForSelect method calls - Improve EventHandleListener to properly determine server port based on read/write configuration and host matching - Fix port detection for read replicas in database tracing This ensures accurate server address and port tracing for both read and write database connections, especially in environments with separate read/write hosts and ports.
|
Warning Rate limit exceeded@huangdijia has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 57 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
Walkthrough添加了常量 Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as 调用者
participant Aspect as DbConnectionAspect
participant Context as Context
participant Listener as EventHandleListener
participant Config as DB配置
Caller->>Aspect: 调用 getPdoForSelect(..., useReadPdo)
Note right of Aspect: 闭包捕获 $proceedingJoinPoint
Aspect->>Context: 设置 TRACE_DB_USE_READ_PDO = useReadPdo
Aspect-->>Caller: 返回 PDO
Caller->>Listener: 触发 handleDbQueryExecuted 事件
Listener->>Context: 读取 TRACE_DB_USE_READ_PDO
alt TRACE_DB_USE_READ_PDO == true
Listener->>Config: 获取读库 hosts/ports
else TRACE_DB_USE_READ_PDO == false
Listener->>Config: 获取写库 hosts/ports
end
Config-->>Listener: 返回 host/port(或无)
Listener->>Listener: 计算最终 server.address 与 server.port(使用显式或推断或回退)
Listener-->>Collector: 发送事件载荷(含 server.address/server.port)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 需要额外关注的点:
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
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: 4
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/sentry/src/Constants.php(1 hunks)src/sentry/src/Tracing/Aspect/DbConnectionAspect.php(1 hunks)src/sentry/src/Tracing/Listener/EventHandleListener.php(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/sentry/src/Tracing/Listener/EventHandleListener.php (2)
src/sentry/src/Util/Carrier.php (2)
get(118-121)has(113-116)src/sentry/src/Constants.php (1)
Constants(14-43)
src/sentry/src/Tracing/Aspect/DbConnectionAspect.php (2)
src/sentry/src/Tracing/Listener/EventHandleListener.php (1)
process(123-168)src/sentry/src/Constants.php (1)
Constants(14-43)
⏰ 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). (6)
- GitHub Check: Test on PHP 8.3 with Swoole 5.1.8
- GitHub Check: Test on PHP 8.2 with Swoole 6.1.2
- GitHub Check: Test on PHP 8.3 with Swoole 6.0.2
- GitHub Check: Test on PHP 8.1 with Swoole 6.1.2
- GitHub Check: Test on PHP 8.3 with Swoole 5.1.8
- GitHub Check: Test on PHP 8.2 with Swoole 5.1.8
🔇 Additional comments (2)
src/sentry/src/Constants.php (1)
18-19: 常量定义符合规范新增的
TRACE_DB_USE_READ_PDO常量定义清晰,遵循了现有的命名模式,用于标识是否使用读取 PDO 连接。src/sentry/src/Tracing/Listener/EventHandleListener.php (1)
213-214: 服务器地址和端口的动态计算实现正确成功地将静态的
TRACE_DB_SERVER_ADDRESS和TRACE_DB_SERVER_PORT替换为基于读写配置动态计算的$host和$port,这样可以准确反映读写副本的实际连接信息。
* fix: improve database read/write connection tracing - Add TRACE_DB_USE_READ_PDO constant to track read PDO usage - Enhance DbConnectionAspect to detect getPdoForSelect method calls - Improve EventHandleListener to properly determine server port based on read/write configuration and host matching - Fix port detection for read replicas in database tracing This ensures accurate server address and port tracing for both read and write database connections, especially in environments with separate read/write hosts and ports. * fix: 优化数据库连接主机和端口的选择逻辑 * fix: 优化数据库配置获取逻辑以支持更灵活的连接设置 * fix: 使用 array_search 优化数据库主机查找逻辑 * fix: 修复数据库配置获取逻辑以使用正确的主机地址 --------- Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
Summary
This PR improves database connection tracing by enhancing the accuracy of server address and port detection for read/write connections.
Changes
TRACE_DB_USE_READ_PDOconstant to track read PDO usageDbConnectionAspectto detectgetPdoForSelectmethod calls and track theuseReadPdoparameterEventHandleListenerto properly determine server port based on read/write configuration and host matchingProblem Solved
Previously, the tracing system had difficulty accurately determining the correct server port for read/write connections, especially in environments with separate read/write hosts and ports. This could lead to incorrect server address and port information being recorded in traces.
Implementation Details
The solution tracks whether a read PDO is being used and then looks up the appropriate host/port configuration from the database config based on the read/write context. This ensures that:
Test Plan
Related Issues
This addresses tracing accuracy issues in environments with separate read/write database configurations.
Summary by CodeRabbit
发布说明
新功能
改进
✏️ Tip: You can customize this high-level summary in your review settings.