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/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, 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..c5b18195f --- /dev/null +++ b/src/sentry/src/Tracing/Aspect/ViewRenderAspect.php @@ -0,0 +1,64 @@ +feature->isTracingSpanEnabled('view')) { + 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 = [ + 'view.mode' => $mode, + 'view.engine' => $engine, + 'view.template' => $template, + 'view.data' => $arguments['data'] ?? [], + ]; + + return trace( + fn (Scope $scope) => $proceedingJoinPoint->process(), + SpanContext::make() + ->setOp('view.render') + ->setDescription($template) + ->setOrigin('auto.view') + ->setData($data) + ); + } +}