Skip to content

Conversation

@huangdijia
Copy link
Contributor

@huangdijia huangdijia commented Nov 6, 2025

Summary

  • Upgraded sentry/sentry from ^4.16.0 to ^4.18.0 in both root and sentry package composer.json files
  • Refactored LogsHandler class to leverage parent class implementation and reduce code duplication
  • Added #[Override] attribute for improved type safety and maintainability

Changes

Dependency Updates

  • Updated sentry/sentry requirement from ^4.16.0 to ^4.18.0 in composer.json
  • Updated sentry/sentry requirement from ^4.16.0 to ^4.18.0 in src/sentry/composer.json

Code Refactoring (LogsHandler)

  • Removed duplicate handle() method implementation
  • Introduced compileAttributes() method with #[Override] attribute to customize attribute compilation
  • Leverages parent class's handle() method for better maintainability
  • Maintains same functionality while reducing lines of code (31 deletions, 14 insertions)
  • Follows DRY (Don't Repeat Yourself) principles

Benefits

  1. Latest Features: Access to Sentry SDK 4.18.0 improvements and bug fixes
  2. Better Code Maintainability: Reduced code duplication by using parent class implementation
  3. Type Safety: Added #[Override] attribute for compile-time verification
  4. Cleaner Architecture: Separation of concerns by only overriding what's necessary

Test plan

  • Verify Sentry logs are still captured correctly
  • Confirm log context and extra data are properly aggregated
  • Ensure logger channel and group attributes are preserved
  • Test that exception handling in logs works as expected
  • Validate compatibility with Sentry SDK 4.18.0 features

Summary by CodeRabbit

发布说明

  • 依赖升级

    • 更新了日志处理库的依赖版本,获取最新的功能和修复。
  • 改进

    • 优化了内部日志属性编译机制,提升系统稳定性。

- Upgrade sentry/sentry from ^4.16.0 to ^4.18.0 in root and sentry package
- Refactor LogsHandler to use parent class's handle() method by overriding compileAttributes()
- Add #[Override] attribute for better type safety
- Simplify code by removing duplicate logic and leveraging parent implementation
- Improve code maintainability by following DRY principles
@coderabbitai
Copy link

coderabbitai bot commented Nov 6, 2025

总览

此PR更新了两个composer.json文件中的sentry/sentry依赖版本(从^4.16.0升级至^4.18.0),并重构了LogsHandler类的实现方式,将公开的handle方法替换为受保护的compileAttributes方法,改变了属性编译逻辑。

变更

文件类别 / 文件路径 变更摘要
依赖版本更新
composer.json, src/sentry/composer.json
sentry/sentry依赖约束从^4.16.0更新至^4.18.0
Monolog处理器重构
src/sentry/src/Monolog/LogsHandler.php
将公开方法handle($record): bool替换为受保护方法compileAttributes($record): array;新方法无条件返回合并后的context、extra、logger channel、logger group和sentry origin数组;移除原有的处理检查和日志聚合逻辑;添加#[Override]属性

预估代码审查工作量

🎯 3 (中等) | ⏱️ ~20 分钟

需要特别关注的区域:

  • src/sentry/src/Monolog/LogsHandler.php — 方法签名和行为发生重大变化,需确认新的compileAttributes方法是否被其他组件正确调用,且原有的处理逻辑移除是否有意为之
  • 验证#[Override]属性的有效性及其在继承层级中的准确性
  • 确认依赖版本升级后是否存在破坏性变更需要适配

可能相关的PR

诗集

🐰 Sentry日志被重拾,
属性编译换新着,
版本升级跃新高,
依赖稳定齐步调——
受保护的方法,守护每份日志芳华 ✨

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the two main changes: upgrading Sentry to v4.18.0 and refactoring LogsHandler, which are clearly reflected in the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/upgrade-sentry-4.18-and-refactor-logs-handler

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c2a529f and 89b00f1.

📒 Files selected for processing (3)
  • composer.json (1 hunks)
  • src/sentry/composer.json (1 hunks)
  • src/sentry/src/Monolog/LogsHandler.php (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
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/Monolog/LogsHandler.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/Monolog/LogsHandler.php
src/*/composer.json

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

src/*/composer.json: Component composer.json must define PSR-4 autoload: "FriendsOfHyperf\{ComponentName}\": "src/"
Component composer.json must set extra.hyperf.config to FriendsOfHyperf\{ComponentName}\ConfigProvider
Component composer.json should require "php": ">=8.1" and "hyperf/framework": "~3.1.0"

Files:

  • src/sentry/composer.json
composer.json

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Root composer.json should require PHP >=8.1

Files:

  • composer.json
🧠 Learnings (2)
📚 Learning: 2025-10-12T13:53:35.783Z
Learnt from: CR
Repo: friendsofhyperf/components PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-12T13:53:35.783Z
Learning: Applies to src/*/composer.json : Component composer.json should require "php": ">=8.1" and "hyperf/framework": "~3.1.0"

Applied to files:

  • src/sentry/composer.json
  • composer.json
📚 Learning: 2025-10-12T13:53:35.783Z
Learnt from: CR
Repo: friendsofhyperf/components PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-12T13:53:35.783Z
Learning: Applies to composer.json : Root composer.json should require PHP >=8.1

Applied to files:

  • src/sentry/composer.json
  • composer.json
🧬 Code graph analysis (1)
src/sentry/src/Monolog/LogsHandler.php (2)
src/facade/src/AsyncQueue.php (1)
  • Override (35-39)
src/macros/output/Hyperf/Collection/Arr.php (1)
  • Arr (17-132)
⏰ 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). (16)
  • GitHub Check: Test on PHP 8.1 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.3 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.3 with Swoole 6.1.1
  • GitHub Check: Test on PHP 8.2 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.1 with Swoole 6.1.1
  • GitHub Check: Test on PHP 8.3 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.2 with Swoole 6.1.1
  • GitHub Check: Test on PHP 8.2 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.1 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.2 with Swoole 6.1.1
  • GitHub Check: Test on PHP 8.3 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.1 with Swoole 6.1.1
  • GitHub Check: Test on PHP 8.2 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.3 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.3 with Swoole 6.1.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.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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@huangdijia huangdijia merged commit 25d2d9d into main Nov 6, 2025
23 checks passed
@huangdijia huangdijia deleted the feat/upgrade-sentry-4.18-and-refactor-logs-handler branch November 6, 2025 00:28
huangdijia added a commit that referenced this pull request Nov 6, 2025
- Upgrade sentry/sentry from ^4.16.0 to ^4.18.0 in root and sentry package
- Refactor LogsHandler to use parent class's handle() method by overriding compileAttributes()
- Add #[Override] attribute for better type safety
- Simplify code by removing duplicate logic and leveraging parent implementation
- Improve code maintainability by following DRY principles

Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants