-
-
Notifications
You must be signed in to change notification settings - Fork 27
refactor(sentry): improve span null safety and consistency in tracing aspects #918
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,14 +12,16 @@ | |
| namespace FriendsOfHyperf\Sentry\Tracing\Aspect; | ||
|
|
||
| use FriendsOfHyperf\Sentry\Aspect\FilesystemAspect as BaseFilesystemAspect; | ||
| use FriendsOfHyperf\Sentry\Tracing\SpanStarter; | ||
| use Hyperf\Di\Aop\ProceedingJoinPoint; | ||
| use Override; | ||
| use Sentry\Tracing\SpanContext; | ||
|
|
||
| use function Sentry\trace; | ||
| use Sentry\Tracing\SpanStatus; | ||
| use Throwable; | ||
|
Comment on lines
+15
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain引入 SpanStarter/SpanStatus/Throwable 合理;请确认 #[Override] 的 PHP 版本兼容性 改造方向对齐其它切面,OK。但请确认项目 PHP 约束≥8.3,否则使用 #[Override] 会导致运行时错误。 建议在仓库根目录执行以下脚本核对 PHP 版本要求与 Override 使用点: 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "PHP requirement in composer.json:"
if command -v jq >/dev/null 2>&1; then
jq -r '.require.php // .require."php"' composer.json
else
rg -nP '"php"\s*:\s*"[^"]+"' composer.json
fi
echo -e "\nAll occurrences of #[Override]:"
rg -nP '#\[\s*Override\s*\]' -C2Length of output: 11740 根据脚本结果,项目的 PHP 版本要求是 让我进一步验证这个版本兼容性问题: Based on the verification results, I can see there's a version compatibility issue that needs to be addressed. PHP 版本约束与 #[Override] 属性不兼容 项目的 composer.json 要求 PHP 建议:
🌐 Web query: 💡 Result: The built-in #[\Override] attribute was added in PHP 8.3 — so PHP >= 8.3.0 is required for the engine to enforce it (in older PHP versions the attribute syntax is ignored). [1][2][3] Sources:
必须修复:#[Override] 与 composer.json 中的 PHP 版本约束冲突 引入 SpanStarter/SpanStatus/Throwable 合理;但仓库根目录 composer.json 要求 PHP >=8.1,而内置属性 #[\Override](等同 #[Override])仅在 PHP >=8.3 可用,仓库中已多处使用该属性(例如 src/sentry/src/Tracing/Aspect/FilesystemAspect.php:25)。
🤖 Prompt for AI Agents |
||
|
|
||
| class FilesystemAspect extends BaseFilesystemAspect | ||
| { | ||
| use SpanStarter; | ||
|
|
||
| #[Override] | ||
| public function process(ProceedingJoinPoint $proceedingJoinPoint) | ||
| { | ||
|
|
@@ -29,13 +31,30 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) | |
|
|
||
| [$op, $description, $data] = $this->getSentryMetadata($proceedingJoinPoint); | ||
|
|
||
| return trace( | ||
| fn () => $proceedingJoinPoint->process(), | ||
| SpanContext::make() | ||
| ->setOp($op) | ||
| ->setData($data) | ||
| ->setOrigin('auto.filesystem') | ||
| ->setDescription($description) | ||
| ); | ||
| $span = $this->startSpan( | ||
| op: $op, | ||
| description: $description, | ||
| origin: 'auto.filesystem', | ||
| )?->setData($data); | ||
|
|
||
huangdijia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| try { | ||
| return $proceedingJoinPoint->process(); | ||
| } catch (Throwable $exception) { | ||
| $span?->setStatus(SpanStatus::internalError()) | ||
| ->setTags([ | ||
| 'error' => 'true', | ||
| 'exception.class' => $exception::class, | ||
| 'exception.message' => $exception->getMessage(), | ||
| 'exception.code' => (string) $exception->getCode(), | ||
| ]); | ||
huangdijia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if ($this->switcher->isTracingExtraTagEnabled('exception.stack_trace')) { | ||
| $span?->setData([ | ||
| 'exception.stack_trace' => (string) $exception, | ||
| ]); | ||
| } | ||
| throw $exception; | ||
| } finally { | ||
| $span?->finish(); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.