Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"Hypervel\\Testbench\\": "src/testbench/src/",
"Hypervel\\Translation\\": "src/translation/src/",
"Hypervel\\Validation\\": "src/validation/src/",
"Hypervel\\Permission\\": "src/permission/src/"
"Hypervel\\Permission\\": "src/permission/src/",
"Hypervel\\Sentry\\": "src/sentry/src/"
},
"files": [
"src/auth/src/Functions.php",
Expand Down Expand Up @@ -132,6 +133,7 @@
"phpseclib/phpseclib": "^3.0",
"psr/log": "^1.0|^2.0|^3.0",
"ramsey/uuid": "^4.7",
"sentry/sentry": "^4.15",
"symfony/error-handler": "^6.3",
"symfony/mailer": "^6.2",
"symfony/process": "^6.2",
Expand Down Expand Up @@ -176,7 +178,8 @@
"hypervel/testbench": "self.version",
"hypervel/translation": "self.version",
"hypervel/validation": "self.version",
"hypervel/permission": "self.version"
"hypervel/permission": "self.version",
"hypervel/sentry": "self.version"
},
"suggest": {
"hyperf/redis": "Required to use redis driver. (^3.1).",
Expand Down Expand Up @@ -253,7 +256,8 @@
"hypervel": {
"providers": [
"Hypervel\\Notifications\\NotificationServiceProvider",
"Hypervel\\Telescope\\TelescopeServiceProvider"
"Hypervel\\Telescope\\TelescopeServiceProvider",
"Hypervel\\Sentry\\SentryServiceProvider"
]
},
"branch-alias": {
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<testsuite name="Hypervel Packages Test Suite">
<directory suffix="Test.php">./tests</directory>
<exclude>./tests/Prompts</exclude>
<exclude>./tests/Sentry</exclude>
</testsuite>
</testsuites>
<php>
Expand Down
5 changes: 3 additions & 2 deletions src/foundation/src/Testing/Concerns/InteractsWithSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Hypervel\Foundation\Testing\Concerns;

use Hypervel\Session\Contracts\Session as SessionContract;
use Hypervel\Session\SessionManager;

trait InteractsWithSession
{
Expand Down Expand Up @@ -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?

$this->app->get(SessionManager::class)->start();
}

return $this;
Expand Down
27 changes: 27 additions & 0 deletions src/sentry/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
The MIT License (MIT)

Copyright (c) 2016 Functional Software, Inc. dba Sentry

Copyright (c) D.J.Hwang

Copyright (c) Hyperf

Copyright (c) Hypervel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
66 changes: 66 additions & 0 deletions src/sentry/class-map/SentrySdk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace Sentry;

use Sentry\State\HubInterface;

use function Hyperf\Support\make;

/**
* @see SentrySdk
*/
class SentrySdk
{
protected static ?HubInterface $hub = null;

/**
* Constructor.
*/
private function __construct()
{
}

/**
* Initializes the SDK with singleton hub.
*/
public static function init(): HubInterface
{
if (is_null(static::$hub)) {
static::$hub = make(HubInterface::class);
}

return static::$hub;
}

/**
* Gets the current hub. Returns the singleton hub instance.
*/
public static function getCurrentHub(): HubInterface
{
if (is_null(static::$hub)) {
static::init();
}

return static::$hub;
}

/**
* Sets the current hub in context but maintains singleton.
*/
public static function setCurrentHub(HubInterface $hub): HubInterface
{
static::$hub = $hub;

return static::$hub;
}

/**
* Get the singleton hub instance directly.
*/
public static function getHub(): ?HubInterface
{
return static::$hub;
}
}
50 changes: 50 additions & 0 deletions src/sentry/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "hypervel/sentry",
"type": "library",
"description": "The sentry component for Hypervel framework.",
"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

"hypervel",
"sentry",
"error-tracking"
],
"authors": [
{
"name": "Albert Chen",
"email": "[email protected]"
}
],
"support": {
"issues": "https://github.com/hypervel/components/issues",
"source": "https://github.com/hypervel/components"
},
"autoload": {
"psr-4": {
"Hypervel\\Sentry\\": "src/"
}
},
"require": {
"php": "^8.2",
"hypervel/cache": "^0.3",
"hypervel/console": "^0.3",
"hypervel/core": "^0.3",
"hypervel/object-pool": "^0.3",
"hypervel/support": "^0.3",
"sentry/sentry": "^4.15.0"
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-main": "0.3-dev"
},
"hypervel": {
"providers": [
"Hypervel\\Sentry\\SentryServiceProvider"
]
}
}
}
137 changes: 137 additions & 0 deletions src/sentry/config/sentry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php

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

* This file is part of Hypervel components.
*
* @link https://github.com/hypervel/components
* @document https://github.com/hypervel/components/blob/main/README.md
* @contact [email protected]
*/

use Hypervel\Sentry\Features\CacheFeature;
use Hypervel\Sentry\Features\ConsoleSchedulingFeature;
use Hypervel\Sentry\Features\DbQueryFeature;
use Hypervel\Sentry\Features\LogFeature;
use Hypervel\Sentry\Features\NotificationsFeature;
use Hypervel\Sentry\Features\QueueFeature;
use Hypervel\Sentry\Integrations\RequestIntegration;
use Hypervel\Validation\ValidationException;
use Sentry\Integration\EnvironmentIntegration;
use Sentry\Integration\FrameContextifierIntegration;
use Sentry\Integration\TransactionIntegration;

use function Hyperf\Support\env;

return [
'dsn' => env('SENTRY_DSN', ''),

// Whether to enable default integrations (includes ModulesIntegration)
'default_integrations' => env('SENTRY_DEFAULT_INTEGRATIONS', false),

// The release version of your application
// Example with dynamic git hash: trim(exec('git log --pretty="%h" -n1 HEAD'))
'release' => env('SENTRY_RELEASE'),

// When left empty or `null` the environment will be used (usually discovered from `APP_ENV` in your `.env`)
'environment' => env('APP_ENV', 'production'),

// @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#sample_rate
'sample_rate' => env('SENTRY_SAMPLE_RATE') === null ? 1.0 : (float) env('SENTRY_SAMPLE_RATE'),

// Switch tracing on/off
'enable_tracing' => env('SENTRY_ENABLE_TRACING', true),

// @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#traces_sample_rate
'traces_sample_rate' => env('SENTRY_TRACES_SAMPLE_RATE') === null ? 1.0 : (float) env('SENTRY_TRACES_SAMPLE_RATE'),

// @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

// return 0;
// }
// return env('SENTRY_TRACES_SAMPLE_RATE') === null ? 1.0 : (float) env('SENTRY_TRACES_SAMPLE_RATE');
// },

// @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#profiles_sample_rate
'profiles_sample_rate' => env('SENTRY_PROFILES_SAMPLE_RATE') === null ? null : (float) env(
'SENTRY_PROFILES_SAMPLE_RATE'
),

// @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#enable_logs
'enable_logs' => env('SENTRY_ENABLE_LOGS', false),

// @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#send_default_pii
'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


'breadcrumbs' => [
// Capture Hypervel cache events (hits, writes etc.) as breadcrumbs
'cache' => env('SENTRY_BREADCRUMBS_CACHE', true),
// Capture SQL queries as breadcrumbs
'sql_queries' => env('SENTRY_BREADCRUMBS_SQL_QUERIES', true),
// Capture SQL query bindings (parameters) in SQL query breadcrumbs
'sql_bindings' => env('SENTRY_BREADCRUMBS_SQL_BINDINGS', false),
// Capture SQL transactions (begin, commit, rollbacks) as breadcrumbs
'sql_transaction' => env('SENTRY_BREADCRUMBS_SQL_TRANSACTION', false),
// Capture queue job information as breadcrumbs
'queue_info' => env('SENTRY_BREADCRUMBS_QUEUE_INFO_ENABLED', true),
// Capture send notifications as breadcrumbs
'notifications' => env('SENTRY_BREADCRUMBS_NOTIFICATIONS_ENABLED', true),
// Capture Guzzle HTTP client requests as breadcrumbs
'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

RequestIntegration::class,
TransactionIntegration::class,
FrameContextifierIntegration::class,
EnvironmentIntegration::class,
],

'features' => [
CacheFeature::class,
QueueFeature::class,
NotificationsFeature::class,
LogFeature::class,
ConsoleSchedulingFeature::class,
DbQueryFeature::class,
],

'ignore_exceptions' => [
ValidationException::class,
],

'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:*?

'gen:*',
'migrate*',
'tinker',
'vendor:publish',
],

// Performance monitoring specific configuration
'tracing' => [
// Capture queue jobs as spans when executed on the sync driver
'queue_jobs' => env('SENTRY_TRACE_QUEUE_JOBS_ENABLED', true),
// Trace queue jobs as their own transactions (this enables tracing for queue jobs)
'queue_job_transactions' => env('SENTRY_TRACE_QUEUE_ENABLED', true),
// Capture Hypervel cache events (hits, writes etc.) as spans
'cache' => env('SENTRY_TRACE_CACHE_ENABLED', true),
// Capture send notifications as spans
'notifications' => env('SENTRY_TRACE_NOTIFICATIONS_ENABLED', true),
// Capture Redis operations as spans (this enables Redis events in Hypervel)
'redis_commands' => env('SENTRY_TRACE_REDIS_COMMANDS', false),
// Capture where the Redis command originated from on the Redis command spans
'redis_origin' => env('SENTRY_TRACE_REDIS_ORIGIN_ENABLED', true),
],

'http_timeout' => (float) env('SENTRY_HTTP_TIMEOUT', 2.0),
];
Loading