Skip to content

Conversation

chinfuyang
Copy link
Contributor

This pull request introduces significant adds Sentry integration to the project. The main changes the Sentry as a dependency and service provider. Additionally, test configuration and package registration have been updated accordingly.

@albertcht albertcht requested a review from Copilot September 16, 2025 15:17
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces comprehensive Sentry integration to the Hypervel framework, adding error tracking and performance monitoring capabilities. The implementation includes a new Sentry package with features for tracking cache operations, database queries, queue jobs, notifications, and console scheduling.

  • Adds complete Sentry SDK integration with custom Hub implementation for coroutine support
  • Implements feature-based architecture for monitoring different framework components
  • Includes comprehensive test coverage for all Sentry features

Reviewed Changes

Copilot reviewed 64 out of 64 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/sentry/ New Sentry package with comprehensive error tracking and performance monitoring
tests/Sentry/ Test suite covering all Sentry features and integrations
tests/Cache/ Updated cache event tests to include new event types
src/cache/ Enhanced cache events with additional event types for better monitoring
src/foundation/ Updated session interaction test helper
composer.json Added Sentry dependency and package registration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +9 to +10
use Sentry\Monolog\LogsHandler;

Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import mismatch - the class imports Sentry\Monolog\LogsHandler but uses a local LogsHandler class. This should import the local class Hypervel\Sentry\Logs\LogsHandler instead.

Suggested change
use Sentry\Monolog\LogsHandler;

Copilot uses AI. Check for mistakes.

Comment on lines +9 to +15
use Sentry\Monolog\LogsHandler;

class LogChannel extends LogManager
{
public function __invoke(array $config = []): Logger
{
$handler = new LogsHandler(
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The handler instantiation uses LogsHandler but should use the correct handler class. Based on the import and usage pattern, this should be new \Hypervel\Sentry\Logs\LogsHandler() to match the local implementation.

Suggested change
use Sentry\Monolog\LogsHandler;
class LogChannel extends LogManager
{
public function __invoke(array $config = []): Logger
{
$handler = new LogsHandler(
// use Sentry\Monolog\LogsHandler; // Removed: use local LogsHandler instead
class LogChannel extends LogManager
{
public function __invoke(array $config = []): Logger
{
$handler = new \Hypervel\Sentry\Logs\LogsHandler(

Copilot uses AI. Check for mistakes.

Comment on lines 182 to 184
private $message;

public function __construct($message = null)
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property $message should have proper type declaration. It should be declared as private ?string $message; and the constructor parameter should be typed as ?string $message = null.

Suggested change
private $message;
public function __construct($message = null)
private ?string $message;
public function __construct(?string $message = null)

Copilot uses AI. Check for mistakes.

Comment on lines 182 to 184
private $message;

public function __construct($message = null)
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property $message should have proper type declaration. It should be declared as private ?string $message; and the constructor parameter should be typed as ?string $message = null.

Suggested change
private $message;
public function __construct($message = null)
private ?string $message;
public function __construct(?string $message = null)

Copilot uses AI. Check for mistakes.

Comment on lines +180 to +183
\sprintf(
'Transaction [%s] was started but tracing is not enabled.',
(string) $transaction->getTraceId()
),
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Use the global sprintf function instead of \sprintf for consistency with the rest of the codebase. The leading backslash is unnecessary here.

Copilot uses AI. Check for mistakes.

Comment on lines +221 to +225
\sprintf(
'Transaction [%s] was started but not sampled because sample rate (decided by %s) is invalid.',
(string) $transaction->getTraceId(),
$sampleSource
),
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Use the global sprintf function instead of \sprintf for consistency. This pattern appears multiple times in the file and should be addressed consistently.

Copilot uses AI. Check for mistakes.

@albertcht albertcht added the feature New feature or request label Sep 17, 2025
@@ -37,8 +38,8 @@ public function session(array $data): static
*/
protected function startSession(): static
{
if (! $this->app->get(SessionContract::class)->isStarted()) {
$this->app->get(SessionContract::class)->start();
if (! $this->app->get(SessionManager::class)->isStarted()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to modify this part?

"license": "MIT",
"keywords": [
"php",
"hyperf",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this package is designed for Hypervel only


declare(strict_types=1);

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this section


// @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#traces_sampler
// 'traces_sampler' => function (Sentry\Tracing\SamplingContext $context): float {
// if (str_contains($context->getTransactionContext()->getDescription(), '/health')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no health route in hypervel

],

'ignore_transactions' => [
'GET /health',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no health route in hypervel

],

'ignore_commands' => [
'crontab:run',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding make:*?

class CoroutineAspect extends AbstractAspect
{
public array $classes = [
'Hypervel\Coroutine\Coroutine::create',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be Hyperf\Coroutine\Coroutine::create here?

public function handleScheduledTaskStarting(ScheduledTaskStarting $event): void
{
// There is nothing for us to track if it's a background task since it will be handled by a separate process
if ($event->task->runInBackground) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tasks which are marked as runInBackground will be executed in coroutines.


public function register(): void
{
$logger = $this->container->get(LoggerInterface::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it a redundant logger here?

});
}

protected function getClientIp(): ?string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get from hypervel's request?

\Psr\Http\Message\ServerRequestInterface::class,
];

public function process(ProceedingJoinPoint $proceedingJoinPoint)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a process switch here?

new Pool(
$builder->getOptions(),
$this->app,
$this->app->get(ConfigInterface::class)->get('pools.sentry', [])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the config should be located under sentry?

return $builder->setTransport($transport);
});

$this->app->define(ClientInterface::class, function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it's define here, but bind in the following binding?


private function makeBacktraceHelper(): BacktraceHelper
{
return $this->container()->make(BacktraceHelper::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it be singleton here?

'send_default_pii' => env('SENTRY_SEND_DEFAULT_PII', false),

// Must instanceof Psr\Log\LoggerInterface
// 'logger' => Hyperf\Contract\StdoutLoggerInterface::class,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check

'guzzle' => env('SENTRY_BREADCRUMBS_GUZZLE', true),
],

'integrations' => [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check

} catch (Exception $e) {
// We can assume the session store is not available here so there is no session key to retrieve
// We capture a generic exception to avoid breaking the application because some code paths can
// result in an exception other than the expected `Illuminate\Contracts\Container\BindingResolutionException`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants