diff --git a/config/sentry.php b/config/sentry.php index 43eba645..8d3aaa1e 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -10,6 +10,9 @@ // @see https://docs.sentry.io/product/sentry-basics/dsn-explainer/ 'dsn' => env('SENTRY_LARAVEL_DSN', env('SENTRY_DSN')), + // @see https://spotlightjs.com/ + // 'spotlight' => env('SENTRY_SPOTLIGHT', false), + // @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#logger // 'logger' => Sentry\Logger\DebugFileLogger::class, // By default this will log to `storage_path('logs/sentry.log')` diff --git a/src/Sentry/Laravel/BaseServiceProvider.php b/src/Sentry/Laravel/BaseServiceProvider.php index 1ebc494e..bdab21d2 100644 --- a/src/Sentry/Laravel/BaseServiceProvider.php +++ b/src/Sentry/Laravel/BaseServiceProvider.php @@ -25,6 +25,18 @@ protected function hasDsnSet(): bool return !empty($config['dsn']); } + /** + * Check if Spotlight was enabled in the config. + * + * @return bool + */ + protected function hasSpotlightEnabled(): bool + { + $config = $this->getUserConfig(); + + return ($config['spotlight'] ?? false) === true; + } + /** * Retrieve the user configuration. * @@ -42,12 +54,14 @@ protected function getUserConfig(): array * * Because of `traces_sampler` being dynamic we can never be 100% confident but that is also not important. * + * @deprecated since version 4.6. To be removed in version 5.0. + * * @return bool */ protected function couldHavePerformanceTracingEnabled(): bool { $config = $this->getUserConfig(); - return !empty($config['traces_sample_rate']) || !empty($config['traces_sampler']); + return !empty($config['traces_sample_rate']) || !empty($config['traces_sampler']) || ($config['spotlight'] ?? false) === true; } } diff --git a/src/Sentry/Laravel/ServiceProvider.php b/src/Sentry/Laravel/ServiceProvider.php index aa7a1d56..36db3403 100644 --- a/src/Sentry/Laravel/ServiceProvider.php +++ b/src/Sentry/Laravel/ServiceProvider.php @@ -83,7 +83,9 @@ public function boot(): void $this->bootFeatures(); - if ($this->hasDsnSet()) { + // Only register if a DSN is set or Spotlight is enabled + // No events can be sent without a DSN set or Spotlight enabled + if ($this->hasDsnSet() || $this->hasSpotlightEnabled()) { $this->bindEvents(); if ($this->app instanceof Lumen) { @@ -188,7 +190,9 @@ protected function registerFeatures(): void */ protected function bootFeatures(): void { - $bootActive = $this->hasDsnSet(); + // Only register if a DSN is set or Spotlight is enabled + // No events can be sent without a DSN set or Spotlight enabled + $bootActive = $this->hasDsnSet() || $this->hasSpotlightEnabled(); foreach (self::FEATURES as $feature) { try { diff --git a/src/Sentry/Laravel/Tracing/ServiceProvider.php b/src/Sentry/Laravel/Tracing/ServiceProvider.php index b9e524b4..325c8cb4 100644 --- a/src/Sentry/Laravel/Tracing/ServiceProvider.php +++ b/src/Sentry/Laravel/Tracing/ServiceProvider.php @@ -26,8 +26,9 @@ class ServiceProvider extends BaseServiceProvider public function boot(): void { - // If there is no DSN set we register nothing since it's impossible for us to send traces without a DSN set - if (!$this->hasDsnSet()) { + // Only register if a DSN is set or Spotlight is enabled + // No events can be sent without a DSN set or Spotlight enabled + if (!$this->hasDsnSet() && !$this->hasSpotlightEnabled()) { return; }