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
6 changes: 3 additions & 3 deletions src/sentry/src/Aspect/CacheAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace FriendsOfHyperf\Sentry\Aspect;

use Closure;
use FriendsOfHyperf\Sentry\Feature;
use FriendsOfHyperf\Sentry\Integration;
use FriendsOfHyperf\Sentry\Switcher;
use Hyperf\Di\Aop\AbstractAspect;
use Hyperf\Di\Aop\ProceedingJoinPoint;
use Sentry\Breadcrumb;
Expand All @@ -32,7 +32,7 @@ class CacheAspect extends AbstractAspect
'Hyperf\Cache\Driver\*Driver::deleteMultiple',
];

public function __construct(protected Switcher $switcher)
public function __construct(protected Feature $feature)
{
}

Expand All @@ -41,7 +41,7 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
$startTime = microtime(true);

return tap($proceedingJoinPoint->process(), function ($result) use ($proceedingJoinPoint, $startTime) {
if (! $this->switcher->isBreadcrumbEnabled('cache')) {
if (! $this->feature->isBreadcrumbEnabled('cache')) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/sentry/src/Aspect/FilesystemAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace FriendsOfHyperf\Sentry\Aspect;

use FriendsOfHyperf\Sentry\Feature;
use FriendsOfHyperf\Sentry\Integration;
use FriendsOfHyperf\Sentry\Switcher;
use Hyperf\Di\Aop\AbstractAspect;
use Hyperf\Di\Aop\ProceedingJoinPoint;
use Sentry\Breadcrumb;
Expand Down Expand Up @@ -41,13 +41,13 @@ class FilesystemAspect extends AbstractAspect
// More adapter methods can be added here
];

public function __construct(protected Switcher $switcher)
public function __construct(protected Feature $feature)
{
}

public function process(ProceedingJoinPoint $proceedingJoinPoint)
{
if (! $this->switcher->isBreadcrumbEnabled('filesystem')) {
if (! $this->feature->isBreadcrumbEnabled('filesystem')) {
return $proceedingJoinPoint->process();
}

Expand Down
6 changes: 3 additions & 3 deletions src/sentry/src/Aspect/GuzzleHttpClientAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace FriendsOfHyperf\Sentry\Aspect;

use FriendsOfHyperf\Sentry\Feature;
use FriendsOfHyperf\Sentry\Integration;
use FriendsOfHyperf\Sentry\Switcher;
use GuzzleHttp\Client;
use GuzzleHttp\TransferStats;
use Hyperf\Di\Aop\AbstractAspect;
Expand All @@ -29,14 +29,14 @@ class GuzzleHttpClientAspect extends AbstractAspect
Client::class . '::transfer',
];

public function __construct(protected Switcher $switcher)
public function __construct(protected Feature $feature)
{
}

public function process(ProceedingJoinPoint $proceedingJoinPoint)
{
// If the guzzle aspect is disabled, we will not record the request.
if (! $this->switcher->isBreadcrumbEnabled('guzzle')) {
if (! $this->feature->isBreadcrumbEnabled('guzzle')) {
return $proceedingJoinPoint->process();
}

Expand Down
6 changes: 3 additions & 3 deletions src/sentry/src/Aspect/LoggerAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace FriendsOfHyperf\Sentry\Aspect;

use BackedEnum;
use FriendsOfHyperf\Sentry\Feature;
use FriendsOfHyperf\Sentry\Integration;
use FriendsOfHyperf\Sentry\Switcher;
use Hyperf\Di\Aop\AbstractAspect;
use Hyperf\Di\Aop\ProceedingJoinPoint;
use Monolog\DateTimeImmutable;
Expand All @@ -32,14 +32,14 @@ class LoggerAspect extends AbstractAspect
Logger::class . '::addRecord',
];

public function __construct(protected Switcher $switcher)
public function __construct(protected Feature $feature)
{
}

public function process(ProceedingJoinPoint $proceedingJoinPoint)
{
return tap($proceedingJoinPoint->process(), function ($result) use ($proceedingJoinPoint) {
if (! $this->switcher->isBreadcrumbEnabled('logs')) {
if (! $this->feature->isBreadcrumbEnabled('logs')) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/sentry/src/Aspect/RedisAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace FriendsOfHyperf\Sentry\Aspect;

use FriendsOfHyperf\Sentry\Feature;
use FriendsOfHyperf\Sentry\Integration;
use FriendsOfHyperf\Sentry\Switcher;
use Hyperf\Di\Aop\AbstractAspect;
use Hyperf\Di\Aop\ProceedingJoinPoint;
use Hyperf\Redis\Event\CommandExecuted;
Expand All @@ -30,7 +30,7 @@ class RedisAspect extends AbstractAspect
RedisConnection::class . '::__call',
];

public function __construct(protected Switcher $switcher)
public function __construct(protected Feature $feature)
{
}

Expand All @@ -42,7 +42,7 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
return tap($proceedingJoinPoint->process(), function ($result) use ($arguments, $startTime) {
if (
class_exists(CommandExecuted::class)
|| ! $this->switcher->isBreadcrumbEnabled('redis')
|| ! $this->feature->isBreadcrumbEnabled('redis')
) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/sentry/src/Crons/Listener/EventHandleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace FriendsOfHyperf\Sentry\Crons\Listener;

use FriendsOfHyperf\Sentry\Constants;
use FriendsOfHyperf\Sentry\Switcher;
use FriendsOfHyperf\Sentry\Feature;
use Hyperf\Context\Context;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Contract\StdoutLoggerInterface;
Expand All @@ -25,7 +25,7 @@ class EventHandleListener implements ListenerInterface
{
public function __construct(
protected ConfigInterface $config,
protected Switcher $switcher,
protected Feature $feature,
protected StdoutLoggerInterface $logger
) {
}
Expand All @@ -44,7 +44,7 @@ public function listen(): array
*/
public function process(object $event): void
{
if (! $this->switcher->isCronsEnabled()) {
if (! $this->feature->isCronsEnabled()) {
return;
}

Expand Down
71 changes: 71 additions & 0 deletions src/sentry/src/Feature.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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;

use Hyperf\Context\Context;
use Hyperf\Contract\ConfigInterface;
use Sentry\SentrySdk;

class Feature
{
public function __construct(protected ConfigInterface $config)
{
}

public function isEnabled(string $key, bool $default = true): bool
{
return (bool) $this->config->get('sentry.enable.' . $key, $default);
}

public function isBreadcrumbEnabled(string $key, bool $default = true): bool
{
return (bool) $this->config->get('sentry.breadcrumbs.' . $key, $default);
}

public function isTracingEnabled(string $key, bool $default = true): bool
{
if (! $this->config->get('sentry.enable_tracing', true)) {
return false;
}

return (bool) $this->config->get('sentry.tracing.enable.' . $key, $default);
}

public function isTracingSpanEnabled(string $key, bool $default = true): bool
{
if (! SentrySdk::getCurrentHub()->getSpan()) {
return false;
}

return (bool) $this->config->get('sentry.tracing.spans.' . $key, $default);
}

public function isTracingExtraTagEnabled(string $key, bool $default = false): bool
{
return (bool) ($this->config->get('sentry.tracing.extra_tags', [])[$key] ?? $default);
}

public function isCronsEnabled(): bool
{
return (bool) $this->config->get('sentry.crons.enable', true);
}

public static function disableCoroutineTracing(): void
{
Context::set(Constants::DISABLE_COROUTINE_TRACING, true);
}

public static function isDisableCoroutineTracing(): bool
{
return (bool) Context::get(Constants::DISABLE_COROUTINE_TRACING);
}
}
Loading