From 1e62fe8b0ff579a26fc38779a4f0b09a3d552a1b Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Sun, 28 Sep 2025 12:58:41 +0800 Subject: [PATCH 1/3] feat(sentry): add view rendering tracing support - Add ViewRenderAspect to trace Hyperf view rendering operations - Add 'view' tracing span configuration option to sentry.php config - Add feature() helper function to Function.php for easier Feature access - Integrate with existing Feature-based span enablement system --- src/sentry/publish/sentry.php | 1 + src/sentry/src/Function.php | 8 +++ .../src/Tracing/Aspect/ViewRenderAspect.php | 51 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 src/sentry/src/Tracing/Aspect/ViewRenderAspect.php diff --git a/src/sentry/publish/sentry.php b/src/sentry/publish/sentry.php index e97ece50b..88afa449e 100644 --- a/src/sentry/publish/sentry.php +++ b/src/sentry/publish/sentry.php @@ -113,6 +113,7 @@ 'grpc' => env('SENTRY_TRACING_SPANS_GRPC', true), 'redis' => env('SENTRY_TRACING_SPANS_REDIS', true), 'sql_queries' => env('SENTRY_TRACING_SPANS_SQL_QUERIES', true), + 'view' => env('SENTRY_TRACING_SPANS_VIEW', true), ], 'extra_tags' => [ 'exception.stack_trace' => true, diff --git a/src/sentry/src/Function.php b/src/sentry/src/Function.php index 6c3cbb8fd..bfddc6248 100644 --- a/src/sentry/src/Function.php +++ b/src/sentry/src/Function.php @@ -18,6 +18,14 @@ use Sentry\Tracing\Transaction; use Sentry\Tracing\TransactionContext; +/** + * Get the Feature instance from the container. + */ +function feature(): Feature +{ + return ApplicationContext::getContainer()->get(Feature::class); +} + /** * Starts a new Transaction and returns it. This is the entry point to manual tracing instrumentation. */ diff --git a/src/sentry/src/Tracing/Aspect/ViewRenderAspect.php b/src/sentry/src/Tracing/Aspect/ViewRenderAspect.php new file mode 100644 index 000000000..d6799fe93 --- /dev/null +++ b/src/sentry/src/Tracing/Aspect/ViewRenderAspect.php @@ -0,0 +1,51 @@ +feature->isTracingSpanEnabled('view')) { + return $proceedingJoinPoint->process(); + } + + $arguments = $proceedingJoinPoint->arguments['keys'] ?? []; + $template = $arguments['template'] ?? 'unknown'; + $data = $arguments['data'] ?? []; + + return trace( + fn (Scope $scope) => $proceedingJoinPoint->process(), + SpanContext::make() + ->setOp('view.render') + ->setDescription($template) + ->setOrigin('auto.view') + ->setData($data) + ); + } +} From 088e6b2d05128571df4a2683df0e1bec5a107bfc Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Sun, 28 Sep 2025 13:05:02 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20ViewRenderAspect=20?= =?UTF-8?q?=E7=B1=BB=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=AF=B9=E8=A7=86=E5=9B=BE?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E5=92=8C=E5=BC=95=E6=93=8E=E7=9A=84=E8=BF=BD?= =?UTF-8?q?=E8=B8=AA=E6=95=B0=E6=8D=AE=E6=94=B6=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Tracing/Aspect/ViewRenderAspect.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/sentry/src/Tracing/Aspect/ViewRenderAspect.php b/src/sentry/src/Tracing/Aspect/ViewRenderAspect.php index d6799fe93..c5b18195f 100644 --- a/src/sentry/src/Tracing/Aspect/ViewRenderAspect.php +++ b/src/sentry/src/Tracing/Aspect/ViewRenderAspect.php @@ -19,6 +19,10 @@ use function FriendsOfHyperf\Sentry\trace; +/** + * @property string $mode + * @property string $engine + */ class ViewRenderAspect extends AbstractAspect { public array $classes = [ @@ -35,9 +39,18 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) return $proceedingJoinPoint->process(); } + /** @var \Hyperf\View\Render $instance */ + $instance = $proceedingJoinPoint->getInstance(); + [$mode, $engine] = (fn () => [$this->mode ?? '', $this->engine ?? ''])->call($instance); $arguments = $proceedingJoinPoint->arguments['keys'] ?? []; + /** @var string $template */ $template = $arguments['template'] ?? 'unknown'; - $data = $arguments['data'] ?? []; + $data = [ + 'view.mode' => $mode, + 'view.engine' => $engine, + 'view.template' => $template, + 'view.data' => $arguments['data'] ?? [], + ]; return trace( fn (Scope $scope) => $proceedingJoinPoint->process(), From 161d6ed2b3f9bc9496fbb6206043ddb0a05af903 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Sun, 28 Sep 2025 13:07:28 +0800 Subject: [PATCH 3/3] feat(sentry): add ViewRenderAspect to tracing aspects --- src/sentry/src/ConfigProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sentry/src/ConfigProvider.php b/src/sentry/src/ConfigProvider.php index 0f9cbd1cd..03f4d332c 100644 --- a/src/sentry/src/ConfigProvider.php +++ b/src/sentry/src/ConfigProvider.php @@ -41,6 +41,7 @@ public function __invoke(): array Tracing\Aspect\RpcAspect::class, Tracing\Aspect\RedisAspect::class, Tracing\Aspect\TraceAnnotationAspect::class, + Tracing\Aspect\ViewRenderAspect::class, ], 'commands' => [ Command\AboutCommand::class,