-
-
Notifications
You must be signed in to change notification settings - Fork 27
Add Annotation for Sentry Safe Caller #1047
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
|
Warning Rate limit exceeded@huangdijia has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 24 minutes and 40 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 (3)
Walkthrough新增 SafeCaller 注解类与 SafeCallerAspect 切面,并在 ConfigProvider 中注册该切面。切面在被注解的方法执行时捕获异常,调用可选的自定义异常处理器并按需将异常上报到 Sentry,最终返回注解指定的默认值或异常处理结果。 Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as 调用方
participant Aspect as SafeCallerAspect
participant Target as 被装饰方法
participant Handler as exceptionHandler (可选)
participant Sentry as Sentry SDK
Caller->>Aspect: 调用被 `#[SafeCaller]` 装饰的方法
Aspect->>Target: proceed()
alt 正常返回
Target-->>Aspect: 返回结果
Aspect-->>Caller: 返回结果
else 抛出异常
Target-->>Aspect: throw Exception
alt 有自定义 exceptionHandler
Aspect->>Handler: 调用 exceptionHandler(Throwable)
Handler-->>Aspect: 返回值(可用于是否上报)
alt 根据 handler 返回需上报
Aspect->>Sentry: 上报异常
Sentry-->>Aspect: 上报完成
end
else 无 handler
Aspect->>Sentry: 上报异常
Sentry-->>Aspect: 上报完成
end
Aspect-->>Caller: 返回注解中 `$default` 或 handler 指定值
end
Estimated code review effort🎯 3 (中等) | ⏱️ ~20 分钟
Suggested reviewers
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: 1
🧹 Nitpick comments (1)
src/sentry/src/Annotation/SafeCaller.php (1)
20-31: 考虑为属性声明添加说明性注释
$exceptionHandler属性没有类型声明,而$default使用了构造器属性提升。这是因为 PHP 不支持将callable用作类型化属性,只能使用未类型化的属性。虽然当前实现是正确的,但建议添加一个注释说明这个设计决策,以提高代码可读性。
🔎 查看建议的改进
+ /** + * @var null|callable 异常处理函数(注:由于 PHP 限制,callable 不能用作类型化属性) + */ public $exceptionHandler;
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/sentry/src/Annotation/SafeCaller.php(1 hunks)src/sentry/src/Aspect/SafeCallerAspect.php(1 hunks)src/sentry/src/ConfigProvider.php(1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.php
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.php: All PHP files must includedeclare(strict_types=1)at the top
Use PSR-12 coding standards for PHP code formatting
Use 4-space indentation with short array syntax in PHP code
Use.php-cs-fixer.phpconfiguration for PHP code formattingAll PHP files must include a strict_types declaration at the top
**/*.php: Follow project PHP coding standard enforced by php-cs-fixer with PSR-12 style, 4-space indentation, and short array syntax
Maintain type coverage by updating or adding tests when public APIs change; ensurecomposer test:typesstays green before pushing
Files:
src/sentry/src/ConfigProvider.phpsrc/sentry/src/Annotation/SafeCaller.phpsrc/sentry/src/Aspect/SafeCallerAspect.php
src/**/src/**/*.php
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use namespace pattern
FriendsOfHyperf\{ComponentName}for all component classes
Files:
src/sentry/src/ConfigProvider.phpsrc/sentry/src/Annotation/SafeCaller.phpsrc/sentry/src/Aspect/SafeCallerAspect.php
src/*/src/ConfigProvider.php
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Each component must include a
ConfigProvider.phpfile that defines dependencies, commands, listeners, and annotations
Files:
src/sentry/src/ConfigProvider.php
**/src/ConfigProvider.php
📄 CodeRabbit inference engine (CLAUDE.md)
**/src/ConfigProvider.php: Use Hyperf's ConfigProvider pattern for auto-discovery in components, defining dependencies, commands, listeners, aspects, and annotations
Components can publish config files and migrations to user applications through ConfigProvider's publish array
Files:
src/sentry/src/ConfigProvider.php
src/*/src/**/*.php
📄 CodeRabbit inference engine (CLAUDE.md)
src/*/src/**/*.php: Namespace convention for components must follow FriendsOfHyperf{ComponentName}
All code must be coroutine-safe and avoid global state without proper context management, blocking I/O operations, and non-coroutine-safe third-party libraries without wrappers
Use Hyperf's Context API for request-scoped data instead of global state
Follows PSR-12 coding standards and use PHP-CS-Fixer for automatic formatting
Use PHPStan at maximum level for static analysis
Ensure component namespace doesn't conflict with existing Hyperf components or other packages in the ecosystem
Integrate deeply with Hyperf's Dependency Injection container for service registration
Leverage Hyperf's AOP (Aspect-Oriented Programming) for cross-cutting concerns via aspects defined in ConfigProvider
Use Hyperf's Event System to register listeners for framework events in components
All code must support coroutine-based concurrency using Swoole/Swow compatibility
Files:
src/sentry/src/ConfigProvider.phpsrc/sentry/src/Annotation/SafeCaller.phpsrc/sentry/src/Aspect/SafeCallerAspect.php
src/**/*.php
📄 CodeRabbit inference engine (AGENTS.md)
Each component lives in its own subdirectory with PSR-4 namespaces matching
FriendsOfHyperf\*
Files:
src/sentry/src/ConfigProvider.phpsrc/sentry/src/Annotation/SafeCaller.phpsrc/sentry/src/Aspect/SafeCallerAspect.php
🧠 Learnings (2)
📚 Learning: 2025-12-12T05:33:43.947Z
Learnt from: CR
Repo: friendsofhyperf/components PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-12T05:33:43.947Z
Learning: Applies to src/*/src/**/*.php : Leverage Hyperf's AOP (Aspect-Oriented Programming) for cross-cutting concerns via aspects defined in ConfigProvider
Applied to files:
src/sentry/src/ConfigProvider.phpsrc/sentry/src/Aspect/SafeCallerAspect.php
📚 Learning: 2025-12-12T05:33:43.947Z
Learnt from: CR
Repo: friendsofhyperf/components PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-12T05:33:43.947Z
Learning: Applies to **/src/ConfigProvider.php : Use Hyperf's ConfigProvider pattern for auto-discovery in components, defining dependencies, commands, listeners, aspects, and annotations
Applied to files:
src/sentry/src/ConfigProvider.php
🧬 Code graph analysis (3)
src/sentry/src/ConfigProvider.php (1)
src/sentry/src/Aspect/SafeCallerAspect.php (1)
SafeCallerAspect(22-50)
src/sentry/src/Annotation/SafeCaller.php (1)
src/sentry/src/Util/SafeCaller.php (1)
SafeCaller(20-50)
src/sentry/src/Aspect/SafeCallerAspect.php (6)
src/sentry/src/Util/SafeCaller.php (1)
SafeCaller(20-50)src/sentry/class_map/SentrySdk.php (2)
SentrySdk(24-65)getCurrentHub(51-54)src/support/src/Once.php (1)
value(54-73)src/http-client/src/Request.php (1)
method(54-57)src/exception-event/src/Functions.php (1)
report(23-44)src/sentry/src/Listener/EventHandleListener.php (1)
captureException(145-160)
⏰ 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)
- GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
- GitHub Check: Test on PHP 8.1 with Swoole 6.1.3
🔇 Additional comments (4)
src/sentry/src/ConfigProvider.php (1)
23-23: 正确地将新切面集成到 AOP 系统中SafeCallerAspect 已正确添加到 aspects 数组中,遵循了 Hyperf 的 ConfigProvider 自动发现模式。
src/sentry/src/Aspect/SafeCallerAspect.php (2)
24-26: 正确定义了切面触发的注解annotations 属性正确声明了此切面处理的注解类型,符合 Hyperf AOP 规范。
47-47: 返回值处理方式优于工具类版本此实现将异常
$e传递给value()函数,这允许$default为闭包时接收异常参数,提供了比src/sentry/src/Util/SafeCaller.php更灵活的错误处理能力。src/sentry/src/Annotation/SafeCaller.php (1)
17-18: 正确使用 PHP 8 特性和 Hyperf 注解模式注解类正确继承 AbstractAnnotation 并使用 Attribute::TARGET_METHOD 限定作用范围,符合框架规范。
Add null check handling for SafeCallerAnnotation in SafeCallerAspect. If the annotation is not found, proceed with normal execution instead of throwing an error. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
* safe caller * Update SafeCaller.php * fix(sentry): add null check for SafeCallerAnnotation Add null check handling for SafeCallerAnnotation in SafeCallerAspect. If the annotation is not found, proceed with normal execution instead of throwing an error. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * feat(sentry): 添加 Graceful 注解及其处理逻辑 * feat(sentry): 移除 SafeCallerAspect,添加 GracefulAspect * feat(sentry): 移除 SafeCallerAspect 和 SafeCaller 注解 * fix(sentry): 修正 Graceful 注解的类型提示为 null|Graceful * fix(sentry): 更新 Graceful 注解中的中文注释为英文 --------- Co-authored-by: 何泽宏 <hzh@addcn.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
Summary by CodeRabbit
发布说明
✏️ Tip: You can customize this high-level summary in your review settings.