Skip to content

Commit

Permalink
Spotlight improvements (#892)
Browse files Browse the repository at this point in the history
* Enable the SDK if Spotlight is enabled

* Add a way to enable Spotlight using `.env`

* CR

* Update comments
  • Loading branch information
stayallive committed May 24, 2024
1 parent cd604a4 commit 490555d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
3 changes: 3 additions & 0 deletions config/sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')`

Expand Down
16 changes: 15 additions & 1 deletion src/Sentry/Laravel/BaseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
}
}
8 changes: 6 additions & 2 deletions src/Sentry/Laravel/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions src/Sentry/Laravel/Tracing/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 490555d

Please sign in to comment.