Skip to content

Commit

Permalink
Disable storage integration by default (#746)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Bouma <alex@bouma.me>
  • Loading branch information
cleptric and stayallive authored Aug 1, 2023
1 parent 6c3e562 commit 616cbb6
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 28 deletions.
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
# Changelog

## 3.7.1

The Sentry SDK team is happy to announce the immediate availability of Sentry Laravel SDK v3.7.1.

### Bug Fixes

- Performance traces and breadcrumbs for filesystem access are now turned off by default [(#746)](https://github.com/getsentry/sentry-laravel/pull/746)

To enable the feature, you'll need to make some changes in your `config/filesystems.php` file for each disk where you want to enable the tracing filesystem driver.

```php
// For example, if you want to trace the `local` disk, you update the disk config from this:
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'throw' => false,
],

// to this:
'local' => [
'driver' => 'sentry',
'root' => storage_path('app'),
'throw' => false,

'sentry_disk_name' => 'local',
'sentry_original_driver' => 'local',
'sentry_enable_spans' => true,
'sentry_enable_breadcrumbs' => true,
],
```

For each disk, you replace the `driver` key with `sentry` and add the `sentry_original_driver` key with the original driver name.
For us to construct the original driver, you also need to add the `sentry_disk_name` key with the name of the disk.
In addition, you can specify the optional `sentry_enable_spans` and `sentry_enable_breadcrumbs` config keys to turn off that feature for the disk.
These options are enabled by default.

Please note that we replace the driver for the disk with a custom driver that will capture performance traces and breadcrumbs.
This means that relying on the disk to be of a specific type might cause problems.
If you rely on the disk being an instance of `Illuminate\Contracts\Filesystem\Filesystem` or `Illuminate\Contracts\Filesystem\Cloud`, there should be no problem.

## 3.7.0

The Sentry SDK team is happy to announce the immediate availability of Sentry Laravel SDK v3.7.0.
Expand Down
9 changes: 1 addition & 8 deletions config/sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

// @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#traces-sample-rate
'traces_sample_rate' => env('SENTRY_TRACES_SAMPLE_RATE') === null ? null : (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'),

Expand All @@ -37,13 +37,9 @@
// Capture Laravel cache events (hits, writes etc.) as breadcrumbs
'cache' => env('SENTRY_BREADCRUMBS_CACHE_ENABLED', true),


// Capture Livewire components like routes as breadcrumbs
'livewire' => env('SENTRY_BREADCRUMBS_LIVEWIRE_ENABLED', true),

// Capture storage access as breadcrumbs
'storage' => env('SENTRY_BREADCRUMBS_STORAGE_ENABLED', true),

// Capture SQL queries as breadcrumbs
'sql_queries' => env('SENTRY_BREADCRUMBS_SQL_QUERIES_ENABLED', true),

Expand Down Expand Up @@ -77,9 +73,6 @@
// Capture views rendered as spans
'views' => env('SENTRY_TRACE_VIEWS_ENABLED', true),

// Capture storage access as spans
'storage' => env('SENTRY_TRACE_STORAGE_ENABLED', true),

// Capture Livewire components as spans
'livewire' => env('SENTRY_TRACE_LIVEWIRE_ENABLED', true),

Expand Down
22 changes: 4 additions & 18 deletions src/Sentry/Laravel/Features/Storage/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,12 @@ class Integration extends Feature

public function isApplicable(): bool
{
return $this->isTracingFeatureEnabled(self::FEATURE_KEY)
|| $this->isBreadcrumbFeatureEnabled(self::FEATURE_KEY);
// Since we only register the driver this feature is always applicable
return true;
}

public function setup(): void
{
foreach (config('filesystems.disks') as $disk => $config) {
$currentDriver = $config['driver'];

if ($currentDriver === self::STORAGE_DRIVER_NAME) {
continue;
}

config([
"filesystems.disks.{$disk}.driver" => self::STORAGE_DRIVER_NAME,
"filesystems.disks.{$disk}.sentry_disk_name" => $disk,
"filesystems.disks.{$disk}.sentry_original_driver" => $config['driver'],
]);
}

$this->container()->afterResolving(FilesystemManager::class, function (FilesystemManager $filesystemManager): void {
$filesystemManager->extend(
self::STORAGE_DRIVER_NAME,
Expand Down Expand Up @@ -69,8 +55,8 @@ function (Application $application, array $config) use ($filesystemManager): Fil

$defaultData = ['disk' => $disk, 'driver' => $config['driver']];

$recordSpans = $this->isTracingFeatureEnabled(self::FEATURE_KEY);
$recordBreadcrumbs = $this->isBreadcrumbFeatureEnabled(self::FEATURE_KEY);
$recordSpans = $config['sentry_enable_spans'] ?? $this->isTracingFeatureEnabled(self::FEATURE_KEY);
$recordBreadcrumbs = $config['sentry_enable_breadcrumbs'] ?? $this->isBreadcrumbFeatureEnabled(self::FEATURE_KEY);

return $originalFilesystem instanceof CloudFilesystem
? new SentryCloudFilesystem($originalFilesystem, $defaultData, $recordSpans, $recordBreadcrumbs)
Expand Down
24 changes: 22 additions & 2 deletions test/Sentry/Features/StorageIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ class StorageIntegrationTest extends TestCase
{
public function testCreatesSpansFor(): void
{
$this->resetApplicationWithConfig([
'filesystems.disks.local.driver' => 'sentry',
'filesystems.disks.local.sentry_disk_name' => 'local',
'filesystems.disks.local.sentry_enable_spans' => true,
'filesystems.disks.local.sentry_original_driver' => 'local',
]);

$hub = $this->getHubFromContainer();

$transaction = $hub->startTransaction(new TransactionContext);
Expand Down Expand Up @@ -60,7 +67,10 @@ public function testCreatesSpansFor(): void
public function testDoesntCreateSpansWhenDisabled(): void
{
$this->resetApplicationWithConfig([
'sentry.tracing.storage' => false,
'filesystems.disks.local.driver' => 'sentry',
'filesystems.disks.local.sentry_disk_name' => 'local',
'filesystems.disks.local.sentry_enable_spans' => false,
'filesystems.disks.local.sentry_original_driver' => 'local',
]);

$hub = $this->getHubFromContainer();
Expand All @@ -77,6 +87,13 @@ public function testDoesntCreateSpansWhenDisabled(): void

public function testCreatesBreadcrumbsFor(): void
{
$this->resetApplicationWithConfig([
'filesystems.disks.local.driver' => 'sentry',
'filesystems.disks.local.sentry_disk_name' => 'local',
'filesystems.disks.local.sentry_original_driver' => 'local',
'filesystems.disks.local.sentry_enable_breadcrumbs' => true,
]);

Storage::put('foo', 'bar');
$fooContent = Storage::get('foo');
Storage::assertExists('foo', 'bar');
Expand Down Expand Up @@ -120,7 +137,10 @@ public function testCreatesBreadcrumbsFor(): void
public function testDoesntCreateBreadcrumbsWhenDisabled(): void
{
$this->resetApplicationWithConfig([
'sentry.breadcrumbs.storage' => false,
'filesystems.disks.local.driver' => 'sentry',
'filesystems.disks.local.sentry_disk_name' => 'local',
'filesystems.disks.local.sentry_original_driver' => 'local',
'filesystems.disks.local.sentry_enable_breadcrumbs' => false,
]);

Storage::exists('foo');
Expand Down

0 comments on commit 616cbb6

Please sign in to comment.