Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/sentry/publish/sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/sentry/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/sentry/src/Function.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
64 changes: 64 additions & 0 deletions src/sentry/src/Tracing/Aspect/ViewRenderAspect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);
/**
* This file is part of friendsofhyperf/components.
*
* @link https://github.com/friendsofhyperf/components
* @document https://github.com/friendsofhyperf/components/blob/main/README.md
* @contact huangdijia@gmail.com
*/

namespace FriendsOfHyperf\Sentry\Tracing\Aspect;

use FriendsOfHyperf\Sentry\Feature;
use Hyperf\Di\Aop\AbstractAspect;
use Hyperf\Di\Aop\ProceedingJoinPoint;
use Sentry\State\Scope;
use Sentry\Tracing\SpanContext;

use function FriendsOfHyperf\Sentry\trace;

/**
* @property string $mode
* @property string $engine
*/
class ViewRenderAspect extends AbstractAspect
{
public array $classes = [
'Hyperf\View\Render::render',
];

public function __construct(protected Feature $feature)
{
}

public function process(ProceedingJoinPoint $proceedingJoinPoint)
{
if (! $this->feature->isTracingSpanEnabled('view')) {
return $proceedingJoinPoint->process();
}

/** @var \Hyperf\View\Render $instance */
$instance = $proceedingJoinPoint->getInstance();
[$mode, $engine] = (fn () => [$this->mode ?? '<missing_mode>', $this->engine ?? '<missing_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)
);
}
}