-
-
Notifications
You must be signed in to change notification settings - Fork 27
feat(sentry): add integer log level support to LogsHandler #910
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
- Accept int|LogLevel|null in constructor parameter - Automatically convert integer log levels to Sentry LogLevel objects - Maintains backward compatibility with existing LogLevel usage - Improves flexibility for users passing Monolog integer levels
Walkthrough更新 Changes
Sequence Diagram(s)sequenceDiagram
actor Caller
participant LogsHandler as LogsHandler::__construct
participant Converter as getSentryLogLevelFromMonologLevel
participant Parent as parent::__construct
Caller->>LogsHandler: new LogsHandler(group, logLevel, bubble)
alt logLevel is int
LogsHandler->>Converter: convert(monologLevel:int)
Converter-->>LogsHandler: sentryLevel:LogLevel
LogsHandler->>Parent: __construct(..., sentryLevel, ...)
else logLevel is LogLevel/null
LogsHandler->>Parent: __construct(..., logLevel, ...)
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
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.17)At least one path must be specified to analyse. Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. 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: 0
🧹 Nitpick comments (3)
src/sentry/src/Monolog/LogsHandler.php (3)
24-28: 补充构造函数 PHPDoc,说明可接受的整型范围与含义便于 IDE/静态分析与使用者理解(如“传入 Monolog 整型级别:Logger::WARNING 等”)。
可考虑:
public function __construct( protected string $group = 'default', - int|LogLevel|null $logLevel = null, + /** + * @param int|LogLevel|null $logLevel Monolog 整型级别(如 \Monolog\Logger::WARNING)或 Sentry\Logs\LogLevel;null 使用默认 + */ + int|LogLevel|null $logLevel = null, protected bool $bubble = true ) {
29-31: 对非法整型级别增加更友好的错误提示若传入的 int 不可映射,当前会沿用底层异常信息。建议在此处捕获并抛出语义更清晰的 InvalidArgumentException。
- if (is_int($logLevel)) { - $logLevel = self::getSentryLogLevelFromMonologLevel($logLevel); - } + if (is_int($logLevel)) { + try { + $logLevel = self::getSentryLogLevelFromMonologLevel($logLevel); + } catch (\Throwable $e) { + throw new \InvalidArgumentException( + sprintf('Unsupported Monolog integer level: %d', $logLevel), + 0, + $e + ); + } + }
44-44: 拼写小修正:separately注释里 “seperately” → “separately”。
- // Do not collect logs for exceptions, they should be handled seperately by the `Handler` or `captureException` + // Do not collect logs for exceptions, they should be handled separately by the `Handler` or `captureException`
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/sentry/src/Monolog/LogsHandler.php(1 hunks)
⏰ 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.1 with Swoole 5.1.7
- GitHub Check: Test on PHP 8.2 with Swoole 5.1.7
- GitHub Check: Test on PHP 8.3 with Swoole 5.1.7
- 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.2 with Swoole 5.1.7
🔇 Additional comments (1)
src/sentry/src/Monolog/LogsHandler.php (1)
26-26: 签名扩展为 int|LogLevel|null — 总体 LGTM已在 src/sentry/src/Monolog/LogsHandler.php 确认构造函数签名为 int|LogLevel|null;仓库中对 LogsHandler 的实例化尚未定位(上次 rg 搜索未检索到文件)。合并前需核查是否存在传入 string 或 Monolog\Level 的调用,使用下列修正后的搜索脚本复核:
#!/bin/bash set -euo pipefail # 直接实例化 rg -nP -S --hidden --glob '!vendor/**' -C2 'new\s+LogsHandler\s*\(' || true # 可能传入字符串作为第二参数 rg -nP -S --hidden --glob '!vendor/**' -C1 "new\s+LogsHandler\s*\([^,]+,\s*['\"][^'\"]+['\"]" || true # 可能传入 Monolog\Level 常量 rg -nP -S --hidden --glob '!vendor/**' -C1 'new\s+LogsHandler\s*\([^,]+,\s*Monolog\\Level::' || true # DI / 工厂 / 配置 引用 rg -n --hidden --glob '!vendor/**' -C3 'LogsHandler::class' || true rg -n --hidden --glob '!vendor/**' -C3 'LogsHandler' || true
| public function __construct( | ||
| protected string $group = 'default', | ||
| ?LogLevel $logLevel = null, | ||
| int|LogLevel|null $logLevel = null, |
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.
| int|LogLevel|null $logLevel = null, | |
| null|int|LogLevel$logLevel = null, |
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.
这个要改cs-fixer配置吧
- Accept int|LogLevel|null in constructor parameter - Automatically convert integer log levels to Sentry LogLevel objects - Maintains backward compatibility with existing LogLevel usage - Improves flexibility for users passing Monolog integer levels Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
Summary
Changes
?LogLeveltoint|LogLevel|nullgetSentryLogLevelFromMonologLevel()Test plan
Summary by CodeRabbit