Skip to content

Commit 490555d

Browse files
authored
Spotlight improvements (#892)
* Enable the SDK if Spotlight is enabled * Add a way to enable Spotlight using `.env` * CR * Update comments
1 parent cd604a4 commit 490555d

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

config/sentry.php

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
// @see https://docs.sentry.io/product/sentry-basics/dsn-explainer/
1111
'dsn' => env('SENTRY_LARAVEL_DSN', env('SENTRY_DSN')),
1212

13+
// @see https://spotlightjs.com/
14+
// 'spotlight' => env('SENTRY_SPOTLIGHT', false),
15+
1316
// @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#logger
1417
// 'logger' => Sentry\Logger\DebugFileLogger::class, // By default this will log to `storage_path('logs/sentry.log')`
1518

src/Sentry/Laravel/BaseServiceProvider.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ protected function hasDsnSet(): bool
2525
return !empty($config['dsn']);
2626
}
2727

28+
/**
29+
* Check if Spotlight was enabled in the config.
30+
*
31+
* @return bool
32+
*/
33+
protected function hasSpotlightEnabled(): bool
34+
{
35+
$config = $this->getUserConfig();
36+
37+
return ($config['spotlight'] ?? false) === true;
38+
}
39+
2840
/**
2941
* Retrieve the user configuration.
3042
*
@@ -42,12 +54,14 @@ protected function getUserConfig(): array
4254
*
4355
* Because of `traces_sampler` being dynamic we can never be 100% confident but that is also not important.
4456
*
57+
* @deprecated since version 4.6. To be removed in version 5.0.
58+
*
4559
* @return bool
4660
*/
4761
protected function couldHavePerformanceTracingEnabled(): bool
4862
{
4963
$config = $this->getUserConfig();
5064

51-
return !empty($config['traces_sample_rate']) || !empty($config['traces_sampler']);
65+
return !empty($config['traces_sample_rate']) || !empty($config['traces_sampler']) || ($config['spotlight'] ?? false) === true;
5266
}
5367
}

src/Sentry/Laravel/ServiceProvider.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ public function boot(): void
8383

8484
$this->bootFeatures();
8585

86-
if ($this->hasDsnSet()) {
86+
// Only register if a DSN is set or Spotlight is enabled
87+
// No events can be sent without a DSN set or Spotlight enabled
88+
if ($this->hasDsnSet() || $this->hasSpotlightEnabled()) {
8789
$this->bindEvents();
8890

8991
if ($this->app instanceof Lumen) {
@@ -188,7 +190,9 @@ protected function registerFeatures(): void
188190
*/
189191
protected function bootFeatures(): void
190192
{
191-
$bootActive = $this->hasDsnSet();
193+
// Only register if a DSN is set or Spotlight is enabled
194+
// No events can be sent without a DSN set or Spotlight enabled
195+
$bootActive = $this->hasDsnSet() || $this->hasSpotlightEnabled();
192196

193197
foreach (self::FEATURES as $feature) {
194198
try {

src/Sentry/Laravel/Tracing/ServiceProvider.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ class ServiceProvider extends BaseServiceProvider
2626

2727
public function boot(): void
2828
{
29-
// If there is no DSN set we register nothing since it's impossible for us to send traces without a DSN set
30-
if (!$this->hasDsnSet()) {
29+
// Only register if a DSN is set or Spotlight is enabled
30+
// No events can be sent without a DSN set or Spotlight enabled
31+
if (!$this->hasDsnSet() && !$this->hasSpotlightEnabled()) {
3132
return;
3233
}
3334

0 commit comments

Comments
 (0)