From 1ed014a2641ef707792957ea40b04088d614f0c8 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Tue, 1 Aug 2023 12:31:57 +0200 Subject: [PATCH 01/11] Extend Storage classes instead of implementing interfaces --- .../Laravel/Features/Storage/Integration.php | 8 ++--- .../Storage/SentryCloudFilesystem.php | 21 ------------- .../Storage/SentryFilesystemAdapter.php | 30 +++++++++++++++++++ .../Features/Storage/SentryS3V3Adapter.php | 23 ++++++++++++++ ...esystem.php => WrapsFilesystemAdapter.php} | 26 +++++----------- 5 files changed, 65 insertions(+), 43 deletions(-) delete mode 100644 src/Sentry/Laravel/Features/Storage/SentryCloudFilesystem.php create mode 100644 src/Sentry/Laravel/Features/Storage/SentryFilesystemAdapter.php create mode 100644 src/Sentry/Laravel/Features/Storage/SentryS3V3Adapter.php rename src/Sentry/Laravel/Features/Storage/{SentryFilesystem.php => WrapsFilesystemAdapter.php} (89%) diff --git a/src/Sentry/Laravel/Features/Storage/Integration.php b/src/Sentry/Laravel/Features/Storage/Integration.php index 16eef58c..e41b4b53 100644 --- a/src/Sentry/Laravel/Features/Storage/Integration.php +++ b/src/Sentry/Laravel/Features/Storage/Integration.php @@ -2,9 +2,9 @@ namespace Sentry\Laravel\Features\Storage; -use Illuminate\Contracts\Filesystem\Cloud as CloudFilesystem; use Illuminate\Contracts\Filesystem\Filesystem; use Illuminate\Contracts\Foundation\Application; +use Illuminate\Filesystem\AwsS3V3Adapter; use Illuminate\Filesystem\FilesystemManager; use RuntimeException; use Sentry\Laravel\Features\Feature; @@ -58,9 +58,9 @@ function (Application $application, array $config) use ($filesystemManager): Fil $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) - : new SentryFilesystem($originalFilesystem, $defaultData, $recordSpans, $recordBreadcrumbs); + return $originalFilesystem instanceof AwsS3V3Adapter + ? new SentryS3V3Adapter($originalFilesystem, $defaultData, $recordSpans, $recordBreadcrumbs) + : new SentryFilesystemAdapter($originalFilesystem, $defaultData, $recordSpans, $recordBreadcrumbs); } ); }); diff --git a/src/Sentry/Laravel/Features/Storage/SentryCloudFilesystem.php b/src/Sentry/Laravel/Features/Storage/SentryCloudFilesystem.php deleted file mode 100644 index 418be57a..00000000 --- a/src/Sentry/Laravel/Features/Storage/SentryCloudFilesystem.php +++ /dev/null @@ -1,21 +0,0 @@ -withSentry(__FUNCTION__, func_get_args(), $path, compact('path')); - } -} diff --git a/src/Sentry/Laravel/Features/Storage/SentryFilesystemAdapter.php b/src/Sentry/Laravel/Features/Storage/SentryFilesystemAdapter.php new file mode 100644 index 00000000..fedb29ee --- /dev/null +++ b/src/Sentry/Laravel/Features/Storage/SentryFilesystemAdapter.php @@ -0,0 +1,30 @@ +getDriver(), $filesystem->getAdapter(), $filesystem->getConfig()); + } + + $this->filesystem = $filesystem; + $this->defaultData = $defaultData; + $this->recordSpans = $recordSpans; + $this->recordBreadcrumbs = $recordBreadcrumbs; + } +} diff --git a/src/Sentry/Laravel/Features/Storage/SentryS3V3Adapter.php b/src/Sentry/Laravel/Features/Storage/SentryS3V3Adapter.php new file mode 100644 index 00000000..f72845fe --- /dev/null +++ b/src/Sentry/Laravel/Features/Storage/SentryS3V3Adapter.php @@ -0,0 +1,23 @@ +getDriver(), $filesystem->getAdapter(), $filesystem->getConfig(), $filesystem->getClient()); + + $this->filesystem = $filesystem; + $this->defaultData = $defaultData; + $this->recordSpans = $recordSpans; + $this->recordBreadcrumbs = $recordBreadcrumbs; + } +} diff --git a/src/Sentry/Laravel/Features/Storage/SentryFilesystem.php b/src/Sentry/Laravel/Features/Storage/WrapsFilesystemAdapter.php similarity index 89% rename from src/Sentry/Laravel/Features/Storage/SentryFilesystem.php rename to src/Sentry/Laravel/Features/Storage/WrapsFilesystemAdapter.php index 94521927..26d1b6d7 100644 --- a/src/Sentry/Laravel/Features/Storage/SentryFilesystem.php +++ b/src/Sentry/Laravel/Features/Storage/WrapsFilesystemAdapter.php @@ -9,14 +9,7 @@ use Sentry\Tracing\SpanContext; use function Sentry\trace; -/** - * Decorates the underlying filesystem by wrapping all calls to it with tracing. - * - * Parameters such as paths, directories or options are attached to the span as data, - * parameters that contain file contents are omitted due to potential problems with - * payload size or sensitive data. - */ -class SentryFilesystem implements Filesystem +trait WrapsFilesystemAdapter { /** @var Filesystem */ protected $filesystem; @@ -30,14 +23,6 @@ class SentryFilesystem implements Filesystem /** @var bool */ protected $recordBreadcrumbs; - public function __construct(Filesystem $filesystem, array $defaultData, bool $recordSpans, bool $recordBreadcrumbs) - { - $this->filesystem = $filesystem; - $this->defaultData = $defaultData; - $this->recordSpans = $recordSpans; - $this->recordBreadcrumbs = $recordBreadcrumbs; - } - /** * Execute the method on the underlying filesystem and wrap it with tracing and log a breadcrumb. * @@ -130,14 +115,14 @@ public function setVisibility($path, $visibility) return $this->withSentry(__FUNCTION__, func_get_args(), $path, compact('path', 'visibility')); } - public function prepend($path, $data) + public function prepend($path, $data, $separator = PHP_EOL) { $description = is_string($data) ? sprintf('%s (%s)', $path, Filesize::toHuman(strlen($data))) : $path; return $this->withSentry(__FUNCTION__, func_get_args(), $description, compact('path')); } - public function append($path, $data) + public function append($path, $data, $separator = PHP_EOL) { $description = is_string($data) ? sprintf('%s (%s)', $path, Filesize::toHuman(strlen($data))) : $path; @@ -207,6 +192,11 @@ public function deleteDirectory($directory) return $this->withSentry(__FUNCTION__, func_get_args(), $directory, compact('directory')); } + public function url($path) + { + return $this->withSentry(__FUNCTION__, func_get_args(), $path, compact('path')); + } + public function __call($name, $arguments) { return $this->filesystem->{$name}(...$arguments); From db3be5fc109bc08c055d81e93a66b0aa6e393d7e Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Tue, 1 Aug 2023 12:37:40 +0200 Subject: [PATCH 02/11] Simplify configuration --- .../Laravel/Features/Storage/Integration.php | 19 +++++++++++ .../Features/StorageIntegrationTest.php | 32 ++++--------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/Sentry/Laravel/Features/Storage/Integration.php b/src/Sentry/Laravel/Features/Storage/Integration.php index e41b4b53..a8975de8 100644 --- a/src/Sentry/Laravel/Features/Storage/Integration.php +++ b/src/Sentry/Laravel/Features/Storage/Integration.php @@ -21,6 +21,25 @@ public function isApplicable(): bool return true; } + public static function configureDisksWithSentryDriver(bool $enableSpans = true, bool $enableBreadcrumbs = true): 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'], + "filesystems.disks.{$disk}.setnry_enable_spans" => $enableSpans, + "filesystems.disks.{$disk}.setnry_enable_breadcrumbs" => $enableBreadcrumbs, + ]); + } + } + public function setup(): void { $this->container()->afterResolving(FilesystemManager::class, function (FilesystemManager $filesystemManager): void { diff --git a/test/Sentry/Features/StorageIntegrationTest.php b/test/Sentry/Features/StorageIntegrationTest.php index 9f6e41bc..88dc8fe1 100644 --- a/test/Sentry/Features/StorageIntegrationTest.php +++ b/test/Sentry/Features/StorageIntegrationTest.php @@ -3,6 +3,7 @@ namespace Sentry\Laravel\Tests\Features; use Illuminate\Support\Facades\Storage; +use Sentry\Laravel\Features\Storage\Integration; use Sentry\Laravel\Tests\TestCase; use Sentry\Tracing\TransactionContext; @@ -10,13 +11,7 @@ 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', - ]); - + Integration::configureDisksWithSentryDriver(); $hub = $this->getHubFromContainer(); $transaction = $hub->startTransaction(new TransactionContext); @@ -66,12 +61,8 @@ public function testCreatesSpansFor(): void public function testDoesntCreateSpansWhenDisabled(): void { - $this->resetApplicationWithConfig([ - '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', - ]); + Integration::configureDisksWithSentryDriver(false); + $this->resetApplicationWithConfig([]); $hub = $this->getHubFromContainer(); @@ -87,12 +78,7 @@ 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, - ]); + Integration::configureDisksWithSentryDriver(); Storage::put('foo', 'bar'); $fooContent = Storage::get('foo'); @@ -136,12 +122,8 @@ public function testCreatesBreadcrumbsFor(): void public function testDoesntCreateBreadcrumbsWhenDisabled(): 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' => false, - ]); + Integration::configureDisksWithSentryDriver(true, false); + $this->resetApplicationWithConfig([]); Storage::exists('foo'); From 25308fb3088af6714a4406d23fa3ed78fd1977b5 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Tue, 1 Aug 2023 13:07:05 +0200 Subject: [PATCH 03/11] Document improved configuration mechanism --- CHANGELOG.md | 29 +++++++++++++++ .../Laravel/Features/Storage/Integration.php | 37 +++++++++++++------ .../Features/StorageIntegrationTest.php | 19 +++++++--- 3 files changed, 68 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cae2e5fb..7b71ad54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,34 @@ # Changelog +### Features + +- The filesystem adapters for the `sentry` driver now extends the known Laravel classes they decorate, + `Illuminate\Filesystem\FilesystemAdapter` and `Sentry\Laravel\Features\Storage\SentryS3V3Adapter`. + + Enabling the feature can be simplified by wrapping your disks with a call to `Sentry\Laravel\Features\Storage\Integration::withSentryDriver()` + in your `config/filesystems.php` file. + + ```php + 'disks' => Sentry\Laravel\Features\Storage\Integration::withSentryDriver([ + 'local' => [ + 'driver' => 'local', + 'root' => storage_path('app'), + 'throw' => false, + ], + + ... + ]), + ``` + + By default, both spans and breadcrumbs are enabled. + You may disable them by passing the second argument `$enableSpans` or the third argument `$enableBreadcrumbs`. + + ```php + 'disks' => Sentry\Laravel\Features\Storage\Integration::withSentryDriver([ + ... + ], true, false), + ``` + ## 3.7.1 The Sentry SDK team is happy to announce the immediate availability of Sentry Laravel SDK v3.7.1. diff --git a/src/Sentry/Laravel/Features/Storage/Integration.php b/src/Sentry/Laravel/Features/Storage/Integration.php index a8975de8..84fa6c39 100644 --- a/src/Sentry/Laravel/Features/Storage/Integration.php +++ b/src/Sentry/Laravel/Features/Storage/Integration.php @@ -21,23 +21,38 @@ public function isApplicable(): bool return true; } - public static function configureDisksWithSentryDriver(bool $enableSpans = true, bool $enableBreadcrumbs = true): void + /** + * Decorates the disk configurations with Sentry driver configuration. + * + * This replaces the drivers with a custom driver that will capture performance traces and breadcrumbs. + * The custom driver will be an instance of @see \Sentry\Laravel\Features\Storage\SentryS3V3Adapter + * if the original driver was an @see \Illuminate\Filesystem\AwsS3V3Adapter, + * and an instance of @see \Sentry\Laravel\Features\Storage\SentryFilesystemAdapter + * which extends @see \Illuminate\Filesystem\FilesystemAdapter in all other cases. + * You might run into problems if you expect another specific driver class. + * + * @param array> $originalDisks + * + * @return array> + */ + public static function withSentryDriver(array $originalDisks, bool $enableSpans = true, bool $enableBreadcrumbs = true): array { - foreach (config('filesystems.disks') as $disk => $config) { + $disksWithSentryDriver = []; + foreach ($originalDisks as $disk => $config) { $currentDriver = $config['driver']; - if ($currentDriver === self::STORAGE_DRIVER_NAME) { - continue; + if ($currentDriver !== self::STORAGE_DRIVER_NAME) { + $config['driver'] = self::STORAGE_DRIVER_NAME; + $config['sentry_disk_name'] = $disk; + $config['sentry_original_driver'] = $currentDriver; + $config['sentry_enable_spans'] = $enableSpans; + $config['sentry_enable_breadcrumbs'] = $enableBreadcrumbs; } - config([ - "filesystems.disks.{$disk}.driver" => self::STORAGE_DRIVER_NAME, - "filesystems.disks.{$disk}.sentry_disk_name" => $disk, - "filesystems.disks.{$disk}.sentry_original_driver" => $config['driver'], - "filesystems.disks.{$disk}.setnry_enable_spans" => $enableSpans, - "filesystems.disks.{$disk}.setnry_enable_breadcrumbs" => $enableBreadcrumbs, - ]); + $disksWithSentryDriver[$disk] = $config; } + + return $disksWithSentryDriver; } public function setup(): void diff --git a/test/Sentry/Features/StorageIntegrationTest.php b/test/Sentry/Features/StorageIntegrationTest.php index 88dc8fe1..f81364bd 100644 --- a/test/Sentry/Features/StorageIntegrationTest.php +++ b/test/Sentry/Features/StorageIntegrationTest.php @@ -11,7 +11,10 @@ class StorageIntegrationTest extends TestCase { public function testCreatesSpansFor(): void { - Integration::configureDisksWithSentryDriver(); + $this->resetApplicationWithConfig([ + 'filesystems.disks' => Integration::withSentryDriver(config('filesystems.disks')), + ]); + $hub = $this->getHubFromContainer(); $transaction = $hub->startTransaction(new TransactionContext); @@ -61,8 +64,9 @@ public function testCreatesSpansFor(): void public function testDoesntCreateSpansWhenDisabled(): void { - Integration::configureDisksWithSentryDriver(false); - $this->resetApplicationWithConfig([]); + $this->resetApplicationWithConfig([ + 'filesystems.disks' => Integration::withSentryDriver(config('filesystems.disks'), false), + ]); $hub = $this->getHubFromContainer(); @@ -78,7 +82,9 @@ public function testDoesntCreateSpansWhenDisabled(): void public function testCreatesBreadcrumbsFor(): void { - Integration::configureDisksWithSentryDriver(); + $this->resetApplicationWithConfig([ + 'filesystems.disks' => Integration::withSentryDriver(config('filesystems.disks')), + ]); Storage::put('foo', 'bar'); $fooContent = Storage::get('foo'); @@ -122,8 +128,9 @@ public function testCreatesBreadcrumbsFor(): void public function testDoesntCreateBreadcrumbsWhenDisabled(): void { - Integration::configureDisksWithSentryDriver(true, false); - $this->resetApplicationWithConfig([]); + $this->resetApplicationWithConfig([ + 'filesystems.disks' => Integration::withSentryDriver(config('filesystems.disks'), true, false), + ]); Storage::exists('foo'); From a9d581748edb20d1e85e012d0b4f75556e6c7d9e Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Tue, 1 Aug 2023 13:11:55 +0200 Subject: [PATCH 04/11] Improve changelog --- CHANGELOG.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b71ad54..18b43594 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,11 @@ ### Features -- The filesystem adapters for the `sentry` driver now extends the known Laravel classes they decorate, - `Illuminate\Filesystem\FilesystemAdapter` and `Sentry\Laravel\Features\Storage\SentryS3V3Adapter`. +- The filesystem adapters for the `sentry` driver now extend the well-known Laravel classes they decorate, + `Illuminate\Filesystem\FilesystemAdapter` and `Illuminate\Filesystem\AwsS3V3Adapter`. - Enabling the feature can be simplified by wrapping your disks with a call to `Sentry\Laravel\Features\Storage\Integration::withSentryDriver()` + Enabling the feature can be simplified by wrapping the configuration for your disks + with a call to `Sentry\Laravel\Features\Storage\Integration::withSentryDriver()` in your `config/filesystems.php` file. ```php @@ -26,7 +27,7 @@ ```php 'disks' => Sentry\Laravel\Features\Storage\Integration::withSentryDriver([ ... - ], true, false), + ], /* enableSpans: */ true, /* enableBreadcrumbs: */ false), ``` ## 3.7.1 From 0ad5bd28a10c32930c9876ff5dc0f49783eea842 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Tue, 1 Aug 2023 15:30:01 +0200 Subject: [PATCH 05/11] Enable selective disk configuration --- CHANGELOG.md | 27 +++++++++-- .../Laravel/Features/Storage/Integration.php | 48 ++++++++++++------- .../Features/StorageIntegrationTest.php | 8 ++-- 3 files changed, 58 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18b43594..04b7d5b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,12 +5,13 @@ - The filesystem adapters for the `sentry` driver now extend the well-known Laravel classes they decorate, `Illuminate\Filesystem\FilesystemAdapter` and `Illuminate\Filesystem\AwsS3V3Adapter`. - Enabling the feature can be simplified by wrapping the configuration for your disks - with a call to `Sentry\Laravel\Features\Storage\Integration::withSentryDriver()` + Enabling the feature can be simplified by wrapping the configuration for all disks + with a call to `Sentry\Laravel\Features\Storage\Integration::configureDisks()` in your `config/filesystems.php` file. ```php - 'disks' => Sentry\Laravel\Features\Storage\Integration::withSentryDriver([ + 'disks' => Sentry\Laravel\Features\Storage\Integration::configureDisks([ + 'local' => [ 'driver' => 'local', 'root' => storage_path('app'), @@ -25,11 +26,29 @@ You may disable them by passing the second argument `$enableSpans` or the third argument `$enableBreadcrumbs`. ```php - 'disks' => Sentry\Laravel\Features\Storage\Integration::withSentryDriver([ + 'disks' => Sentry\Laravel\Features\Storage\Integration::configureDisks([ ... ], /* enableSpans: */ true, /* enableBreadcrumbs: */ false), ``` + Alternatively, you can enable this feature only for selected disks. + + ```php + 'disks' => [ + + 'local' => [ + 'driver' => 'local', + 'root' => storage_path('app'), + 'throw' => false, + ], + + + 's3' => Sentry\Laravel\Features\Storage\Integration::configureDisk('s3', [ + ... + ]), + ], + ``` + ## 3.7.1 The Sentry SDK team is happy to announce the immediate availability of Sentry Laravel SDK v3.7.1. diff --git a/src/Sentry/Laravel/Features/Storage/Integration.php b/src/Sentry/Laravel/Features/Storage/Integration.php index 84fa6c39..2a7de81e 100644 --- a/src/Sentry/Laravel/Features/Storage/Integration.php +++ b/src/Sentry/Laravel/Features/Storage/Integration.php @@ -22,7 +22,7 @@ public function isApplicable(): bool } /** - * Decorates the disk configurations with Sentry driver configuration. + * Decorates the configuration for all disks with Sentry driver configuration. * * This replaces the drivers with a custom driver that will capture performance traces and breadcrumbs. * The custom driver will be an instance of @see \Sentry\Laravel\Features\Storage\SentryS3V3Adapter @@ -31,28 +31,42 @@ public function isApplicable(): bool * which extends @see \Illuminate\Filesystem\FilesystemAdapter in all other cases. * You might run into problems if you expect another specific driver class. * - * @param array> $originalDisks + * @param array> $diskConfigs * * @return array> */ - public static function withSentryDriver(array $originalDisks, bool $enableSpans = true, bool $enableBreadcrumbs = true): array + public static function configureDisks(array $diskConfigs, bool $enableSpans = true, bool $enableBreadcrumbs = true): array { - $disksWithSentryDriver = []; - foreach ($originalDisks as $disk => $config) { - $currentDriver = $config['driver']; - - if ($currentDriver !== self::STORAGE_DRIVER_NAME) { - $config['driver'] = self::STORAGE_DRIVER_NAME; - $config['sentry_disk_name'] = $disk; - $config['sentry_original_driver'] = $currentDriver; - $config['sentry_enable_spans'] = $enableSpans; - $config['sentry_enable_breadcrumbs'] = $enableBreadcrumbs; - } - - $disksWithSentryDriver[$disk] = $config; + $diskConfigsWithSentryDriver = []; + foreach ($diskConfigs as $diskName => $diskConfig) { + $diskConfigsWithSentryDriver[$diskName] = static::configureDisk($diskName, $diskConfig, $enableSpans, $enableBreadcrumbs); } - return $disksWithSentryDriver; + return $diskConfigsWithSentryDriver; + } + + /** + * Decorates the configuration for a single disk with Sentry driver configuration. + * + * @see self::configureDisks() + * + * @param array $diskConfig + * + * @return array + */ + public static function configureDisk(string $diskName, array $diskConfig, bool $enableSpans = true, bool $enableBreadcrumbs = true): array + { + $currentDriver = $diskConfig['driver']; + + if ($currentDriver !== self::STORAGE_DRIVER_NAME) { + $diskConfig['driver'] = self::STORAGE_DRIVER_NAME; + $diskConfig['sentry_disk_name'] = $diskName; + $diskConfig['sentry_original_driver'] = $currentDriver; + $diskConfig['sentry_enable_spans'] = $enableSpans; + $diskConfig['sentry_enable_breadcrumbs'] = $enableBreadcrumbs; + } + + return $diskConfig; } public function setup(): void diff --git a/test/Sentry/Features/StorageIntegrationTest.php b/test/Sentry/Features/StorageIntegrationTest.php index f81364bd..18efd85d 100644 --- a/test/Sentry/Features/StorageIntegrationTest.php +++ b/test/Sentry/Features/StorageIntegrationTest.php @@ -12,7 +12,7 @@ class StorageIntegrationTest extends TestCase public function testCreatesSpansFor(): void { $this->resetApplicationWithConfig([ - 'filesystems.disks' => Integration::withSentryDriver(config('filesystems.disks')), + 'filesystems.disks' => Integration::configureDisks(config('filesystems.disks')), ]); $hub = $this->getHubFromContainer(); @@ -65,7 +65,7 @@ public function testCreatesSpansFor(): void public function testDoesntCreateSpansWhenDisabled(): void { $this->resetApplicationWithConfig([ - 'filesystems.disks' => Integration::withSentryDriver(config('filesystems.disks'), false), + 'filesystems.disks' => Integration::configureDisks(config('filesystems.disks'), false), ]); $hub = $this->getHubFromContainer(); @@ -83,7 +83,7 @@ public function testDoesntCreateSpansWhenDisabled(): void public function testCreatesBreadcrumbsFor(): void { $this->resetApplicationWithConfig([ - 'filesystems.disks' => Integration::withSentryDriver(config('filesystems.disks')), + 'filesystems.disks' => Integration::configureDisks(config('filesystems.disks')), ]); Storage::put('foo', 'bar'); @@ -129,7 +129,7 @@ public function testCreatesBreadcrumbsFor(): void public function testDoesntCreateBreadcrumbsWhenDisabled(): void { $this->resetApplicationWithConfig([ - 'filesystems.disks' => Integration::withSentryDriver(config('filesystems.disks'), true, false), + 'filesystems.disks' => Integration::configureDisks(config('filesystems.disks'), true, false), ]); Storage::exists('foo'); From 618434caa77893437cc00a2b45d89cd3fae4b869 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Tue, 1 Aug 2023 15:48:23 +0200 Subject: [PATCH 06/11] Always register driver --- src/Sentry/Laravel/Features/Storage/Integration.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Sentry/Laravel/Features/Storage/Integration.php b/src/Sentry/Laravel/Features/Storage/Integration.php index 2a7de81e..6fec58cb 100644 --- a/src/Sentry/Laravel/Features/Storage/Integration.php +++ b/src/Sentry/Laravel/Features/Storage/Integration.php @@ -70,6 +70,18 @@ public static function configureDisk(string $diskName, array $diskConfig, bool $ } public function setup(): void + { + $this->registerDriver(); + } + + public function setupInactive(): void + { + // Required when inactive because the disks configuration is static, + // without this it fails with: "Driver [sentry] is not supported.". + $this->registerDriver(); + } + + protected function registerDriver(): void { $this->container()->afterResolving(FilesystemManager::class, function (FilesystemManager $filesystemManager): void { $filesystemManager->extend( From 0b7fe98b672406e6f493d6835f49256496db0de5 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Thu, 3 Aug 2023 10:20:30 +0200 Subject: [PATCH 07/11] Be even more specific with type of filesystem --- ...temAdapter.php => FilesystemDecorator.php} | 9 +- .../Laravel/Features/Storage/Integration.php | 119 ++++++++++-------- .../Storage/SentryCloudFilesystem.php | 9 ++ .../Features/Storage/SentryFilesystem.php | 18 +++ .../Storage/SentryFilesystemAdapter.php | 9 +- .../Features/Storage/SentryS3V3Adapter.php | 5 +- .../Features/StorageIntegrationTest.php | 4 +- 7 files changed, 108 insertions(+), 65 deletions(-) rename src/Sentry/Laravel/Features/Storage/{WrapsFilesystemAdapter.php => FilesystemDecorator.php} (95%) create mode 100644 src/Sentry/Laravel/Features/Storage/SentryCloudFilesystem.php create mode 100644 src/Sentry/Laravel/Features/Storage/SentryFilesystem.php diff --git a/src/Sentry/Laravel/Features/Storage/WrapsFilesystemAdapter.php b/src/Sentry/Laravel/Features/Storage/FilesystemDecorator.php similarity index 95% rename from src/Sentry/Laravel/Features/Storage/WrapsFilesystemAdapter.php rename to src/Sentry/Laravel/Features/Storage/FilesystemDecorator.php index 176f9752..bd9bbff8 100644 --- a/src/Sentry/Laravel/Features/Storage/WrapsFilesystemAdapter.php +++ b/src/Sentry/Laravel/Features/Storage/FilesystemDecorator.php @@ -9,7 +9,14 @@ use Sentry\Tracing\SpanContext; use function Sentry\trace; -trait WrapsFilesystemAdapter +/** + * Decorates the underlying filesystem by wrapping all calls to it with tracing. + * + * Parameters such as paths, directories or options are attached to the span as data, + * parameters that contain file contents are omitted due to potential problems with + * payload size or sensitive data. + */ +trait FilesystemDecorator { /** @var Filesystem */ protected $filesystem; diff --git a/src/Sentry/Laravel/Features/Storage/Integration.php b/src/Sentry/Laravel/Features/Storage/Integration.php index 2a6ceaff..f5f07edf 100644 --- a/src/Sentry/Laravel/Features/Storage/Integration.php +++ b/src/Sentry/Laravel/Features/Storage/Integration.php @@ -2,9 +2,11 @@ namespace Sentry\Laravel\Features\Storage; +use Illuminate\Contracts\Filesystem\Cloud as CloudFilesystem; use Illuminate\Contracts\Filesystem\Filesystem; use Illuminate\Contracts\Foundation\Application; use Illuminate\Filesystem\AwsS3V3Adapter; +use Illuminate\Filesystem\FilesystemAdapter; use Illuminate\Filesystem\FilesystemManager; use RuntimeException; use Sentry\Laravel\Features\Feature; @@ -21,54 +23,6 @@ public function isApplicable(): bool return true; } - /** - * Decorates the configuration for all disks with Sentry driver configuration. - * - * This replaces the drivers with a custom driver that will capture performance traces and breadcrumbs. - * The custom driver will be an instance of @see \Sentry\Laravel\Features\Storage\SentryS3V3Adapter - * if the original driver was an @see \Illuminate\Filesystem\AwsS3V3Adapter, - * and an instance of @see \Sentry\Laravel\Features\Storage\SentryFilesystemAdapter - * which extends @see \Illuminate\Filesystem\FilesystemAdapter in all other cases. - * You might run into problems if you expect another specific driver class. - * - * @param array> $diskConfigs - * - * @return array> - */ - public static function configureDisks(array $diskConfigs, bool $enableSpans = true, bool $enableBreadcrumbs = true): array - { - $diskConfigsWithSentryDriver = []; - foreach ($diskConfigs as $diskName => $diskConfig) { - $diskConfigsWithSentryDriver[$diskName] = static::configureDisk($diskName, $diskConfig, $enableSpans, $enableBreadcrumbs); - } - - return $diskConfigsWithSentryDriver; - } - - /** - * Decorates the configuration for a single disk with Sentry driver configuration. - * - * @see self::configureDisks() - * - * @param array $diskConfig - * - * @return array - */ - public static function configureDisk(string $diskName, array $diskConfig, bool $enableSpans = true, bool $enableBreadcrumbs = true): array - { - $currentDriver = $diskConfig['driver']; - - if ($currentDriver !== self::STORAGE_DRIVER_NAME) { - $diskConfig['driver'] = self::STORAGE_DRIVER_NAME; - $diskConfig['sentry_disk_name'] = $diskName; - $diskConfig['sentry_original_driver'] = $currentDriver; - $diskConfig['sentry_enable_spans'] = $enableSpans; - $diskConfig['sentry_enable_breadcrumbs'] = $enableBreadcrumbs; - } - - return $diskConfig; - } - public function setup(): void { $this->registerDriver(); @@ -109,6 +63,7 @@ function (Application $application, array $config) use ($filesystemManager): Fil return $this->resolve($disk); })->bindTo($filesystemManager, FilesystemManager::class); + /** @var Filesystem $originalFilesystem */ $originalFilesystem = $diskResolver($disk, $config); $defaultData = ['disk' => $disk, 'driver' => $config['driver']]; @@ -116,11 +71,73 @@ function (Application $application, array $config) use ($filesystemManager): Fil $recordSpans = $config['sentry_enable_spans'] ?? $this->isTracingFeatureEnabled(self::FEATURE_KEY); $recordBreadcrumbs = $config['sentry_enable_breadcrumbs'] ?? $this->isBreadcrumbFeatureEnabled(self::FEATURE_KEY); - return $originalFilesystem instanceof AwsS3V3Adapter - ? new SentryS3V3Adapter($originalFilesystem, $defaultData, $recordSpans, $recordBreadcrumbs) - : new SentryFilesystemAdapter($originalFilesystem, $defaultData, $recordSpans, $recordBreadcrumbs); + if ($originalFilesystem instanceof AwsS3V3Adapter) { + return new SentryS3V3Adapter($originalFilesystem, $defaultData, $recordSpans, $recordBreadcrumbs); + } + + if ($originalFilesystem instanceof FilesystemAdapter) { + return new SentryFilesystemAdapter($originalFilesystem, $defaultData, $recordSpans, $recordBreadcrumbs); + } + + if ($originalFilesystem instanceof CloudFilesystem) { + return new SentryCloudFilesystem($originalFilesystem, $defaultData, $recordSpans, $recordBreadcrumbs); + } + + return new SentryFilesystem($originalFilesystem, $defaultData, $recordSpans, $recordBreadcrumbs); } ); }); } + + /** + * Decorates the configuration for a single disk with Sentry driver configuration. + + * This replaces the driver with a custom driver that will capture performance traces and breadcrumbs. + * + * The custom driver will be an instance of @see \Sentry\Laravel\Features\Storage\SentryS3V3Adapter + * if the original driver is an @see \Illuminate\Filesystem\AwsS3V3Adapter, + * and an instance of @see \Sentry\Laravel\Features\Storage\SentryFilesystemAdapter + * if the original driver is an @see \Illuminate\Filesystem\FilesystemAdapter. + * If the original driver is neither of those, it will be @see \Sentry\Laravel\Features\Storage\SentryFilesystem + * or @see \Sentry\Laravel\Features\Storage\SentryCloudFilesystem based on the contract of the original driver. + * + * You might run into problems if you expect another specific driver class. + * + * @param array $diskConfig + * + * @return array + */ + public static function configureDisk(string $diskName, array $diskConfig, bool $enableSpans = true, bool $enableBreadcrumbs = true): array + { + $currentDriver = $diskConfig['driver']; + + if ($currentDriver !== self::STORAGE_DRIVER_NAME) { + $diskConfig['driver'] = self::STORAGE_DRIVER_NAME; + $diskConfig['sentry_disk_name'] = $diskName; + $diskConfig['sentry_original_driver'] = $currentDriver; + $diskConfig['sentry_enable_spans'] = $enableSpans; + $diskConfig['sentry_enable_breadcrumbs'] = $enableBreadcrumbs; + } + + return $diskConfig; + } + + /** + * Decorates the configuration for all disks with Sentry driver configuration. + * + * @see self::configureDisk() + * + * @param array> $diskConfigs + * + * @return array> + */ + public static function configureDisks(array $diskConfigs, bool $enableSpans = true, bool $enableBreadcrumbs = true): array + { + $diskConfigsWithSentryDriver = []; + foreach ($diskConfigs as $diskName => $diskConfig) { + $diskConfigsWithSentryDriver[$diskName] = static::configureDisk($diskName, $diskConfig, $enableSpans, $enableBreadcrumbs); + } + + return $diskConfigsWithSentryDriver; + } } diff --git a/src/Sentry/Laravel/Features/Storage/SentryCloudFilesystem.php b/src/Sentry/Laravel/Features/Storage/SentryCloudFilesystem.php new file mode 100644 index 00000000..d9e38095 --- /dev/null +++ b/src/Sentry/Laravel/Features/Storage/SentryCloudFilesystem.php @@ -0,0 +1,9 @@ +filesystem = $filesystem; + $this->defaultData = $defaultData; + $this->recordSpans = $recordSpans; + $this->recordBreadcrumbs = $recordBreadcrumbs; + } +} diff --git a/src/Sentry/Laravel/Features/Storage/SentryFilesystemAdapter.php b/src/Sentry/Laravel/Features/Storage/SentryFilesystemAdapter.php index fedb29ee..f135e526 100644 --- a/src/Sentry/Laravel/Features/Storage/SentryFilesystemAdapter.php +++ b/src/Sentry/Laravel/Features/Storage/SentryFilesystemAdapter.php @@ -2,7 +2,6 @@ namespace Sentry\Laravel\Features\Storage; -use Illuminate\Contracts\Filesystem\Filesystem; use Illuminate\Filesystem\FilesystemAdapter; /** @@ -14,13 +13,11 @@ */ class SentryFilesystemAdapter extends FilesystemAdapter { - use WrapsFilesystemAdapter; + use FilesystemDecorator; - public function __construct(Filesystem $filesystem, array $defaultData, bool $recordSpans, bool $recordBreadcrumbs) + public function __construct(FilesystemAdapter $filesystem, array $defaultData, bool $recordSpans, bool $recordBreadcrumbs) { - if ($filesystem instanceof FilesystemAdapter) { - parent::__construct($filesystem->getDriver(), $filesystem->getAdapter(), $filesystem->getConfig()); - } + parent::__construct($filesystem->getDriver(), $filesystem->getAdapter(), $filesystem->getConfig()); $this->filesystem = $filesystem; $this->defaultData = $defaultData; diff --git a/src/Sentry/Laravel/Features/Storage/SentryS3V3Adapter.php b/src/Sentry/Laravel/Features/Storage/SentryS3V3Adapter.php index f72845fe..8403a23e 100644 --- a/src/Sentry/Laravel/Features/Storage/SentryS3V3Adapter.php +++ b/src/Sentry/Laravel/Features/Storage/SentryS3V3Adapter.php @@ -6,10 +6,7 @@ class SentryS3V3Adapter extends AwsS3V3Adapter { - use WrapsFilesystemAdapter; - - /** @var AwsS3V3Adapter */ - protected $filesystem; + use FilesystemDecorator; public function __construct(AwsS3V3Adapter $filesystem, array $defaultData, bool $recordSpans, bool $recordBreadcrumbs) { diff --git a/test/Sentry/Features/StorageIntegrationTest.php b/test/Sentry/Features/StorageIntegrationTest.php index c4735e00..58d2cbf1 100644 --- a/test/Sentry/Features/StorageIntegrationTest.php +++ b/test/Sentry/Features/StorageIntegrationTest.php @@ -155,9 +155,7 @@ public function testDriverWorksWhenDisabled(): void { $this->resetApplicationWithConfig([ 'sentry.dsn' => null, - 'filesystems.disks.local.driver' => 'sentry', - 'filesystems.disks.local.sentry_disk_name' => 'local', - 'filesystems.disks.local.sentry_original_driver' => 'local', + 'filesystems.disks' => Integration::configureDisks(config('filesystems.disks')), ]); Storage::exists('foo'); From 694f106115a9594a30d891c22e18820dafbfb28a Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Thu, 3 Aug 2023 10:22:33 +0200 Subject: [PATCH 08/11] Woops --- src/Sentry/Laravel/Features/Storage/Integration.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Sentry/Laravel/Features/Storage/Integration.php b/src/Sentry/Laravel/Features/Storage/Integration.php index f5f07edf..f8d38cb1 100644 --- a/src/Sentry/Laravel/Features/Storage/Integration.php +++ b/src/Sentry/Laravel/Features/Storage/Integration.php @@ -60,6 +60,7 @@ function (Application $application, array $config) use ($filesystemManager): Fil // This is a "hack" to make sure that the original driver is resolved by the FilesystemManager config(["filesystems.disks.{$disk}" => $config]); + /** @var FilesystemManager $this */ return $this->resolve($disk); })->bindTo($filesystemManager, FilesystemManager::class); From 8884fd2cae75907e4d02f2f8136814e8b1f91b29 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Thu, 3 Aug 2023 10:24:22 +0200 Subject: [PATCH 09/11] Remove duplicated comment --- .../Laravel/Features/Storage/SentryFilesystemAdapter.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Sentry/Laravel/Features/Storage/SentryFilesystemAdapter.php b/src/Sentry/Laravel/Features/Storage/SentryFilesystemAdapter.php index f135e526..dac830e3 100644 --- a/src/Sentry/Laravel/Features/Storage/SentryFilesystemAdapter.php +++ b/src/Sentry/Laravel/Features/Storage/SentryFilesystemAdapter.php @@ -4,13 +4,6 @@ use Illuminate\Filesystem\FilesystemAdapter; -/** - * Decorates the underlying filesystem by wrapping all calls to it with tracing. - * - * Parameters such as paths, directories or options are attached to the span as data, - * parameters that contain file contents are omitted due to potential problems with - * payload size or sensitive data. - */ class SentryFilesystemAdapter extends FilesystemAdapter { use FilesystemDecorator; From 33f464f5eb4f92ab0c8dea7aa5b63038df4205d6 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Thu, 3 Aug 2023 11:29:00 +0200 Subject: [PATCH 10/11] Move methods to specific decorators when applicable --- .../Storage/CloudFilesystemDecorator.php | 13 ++++++++ .../Storage/FilesystemAdapterDecorator.php | 33 +++++++++++++++++++ .../Features/Storage/FilesystemDecorator.php | 23 ------------- .../Storage/SentryCloudFilesystem.php | 11 ++++++- .../Storage/SentryFilesystemAdapter.php | 2 +- .../Features/Storage/SentryS3V3Adapter.php | 2 +- 6 files changed, 58 insertions(+), 26 deletions(-) create mode 100644 src/Sentry/Laravel/Features/Storage/CloudFilesystemDecorator.php create mode 100644 src/Sentry/Laravel/Features/Storage/FilesystemAdapterDecorator.php diff --git a/src/Sentry/Laravel/Features/Storage/CloudFilesystemDecorator.php b/src/Sentry/Laravel/Features/Storage/CloudFilesystemDecorator.php new file mode 100644 index 00000000..3be8dd4d --- /dev/null +++ b/src/Sentry/Laravel/Features/Storage/CloudFilesystemDecorator.php @@ -0,0 +1,13 @@ +withSentry(__FUNCTION__, func_get_args(), $path, compact('path')); + } +} diff --git a/src/Sentry/Laravel/Features/Storage/FilesystemAdapterDecorator.php b/src/Sentry/Laravel/Features/Storage/FilesystemAdapterDecorator.php new file mode 100644 index 00000000..46bd6e4b --- /dev/null +++ b/src/Sentry/Laravel/Features/Storage/FilesystemAdapterDecorator.php @@ -0,0 +1,33 @@ +withSentry(__FUNCTION__, func_get_args(), $path, compact('path')); + } + + public function assertMissing($path) + { + return $this->withSentry(__FUNCTION__, func_get_args(), $path, compact('path')); + } + + public function assertDirectoryEmpty($path) + { + return $this->withSentry(__FUNCTION__, func_get_args(), $path, compact('path')); + } + + public function temporaryUrl($path, $expiration, array $options = []) + { + return $this->withSentry(__FUNCTION__, func_get_args(), $path, compact('path', 'expiration', 'options')); + } + + public function temporaryUploadUrl($path, $expiration, array $options = []) + { + return $this->withSentry(__FUNCTION__, func_get_args(), $path, compact('path', 'expiration', 'options')); + } +} diff --git a/src/Sentry/Laravel/Features/Storage/FilesystemDecorator.php b/src/Sentry/Laravel/Features/Storage/FilesystemDecorator.php index bd9bbff8..175dc36b 100644 --- a/src/Sentry/Laravel/Features/Storage/FilesystemDecorator.php +++ b/src/Sentry/Laravel/Features/Storage/FilesystemDecorator.php @@ -67,24 +67,6 @@ protected function withSentry(string $method, array $args, ?string $description, return $this->filesystem->{$method}(...$args); } - /** @see \Illuminate\Filesystem\FilesystemAdapter::assertExists() */ - public function assertExists($path, $content = null) - { - return $this->withSentry(__FUNCTION__, func_get_args(), $path, compact('path')); - } - - /** @see \Illuminate\Filesystem\FilesystemAdapter::assertMissing() */ - public function assertMissing($path) - { - return $this->withSentry(__FUNCTION__, func_get_args(), $path, compact('path')); - } - - /** @see \Illuminate\Filesystem\FilesystemAdapter::assertDirectoryEmpty() */ - public function assertDirectoryEmpty($path) - { - return $this->withSentry(__FUNCTION__, func_get_args(), $path, compact('path')); - } - public function exists($path) { return $this->withSentry(__FUNCTION__, func_get_args(), $path, compact('path')); @@ -199,11 +181,6 @@ public function deleteDirectory($directory) return $this->withSentry(__FUNCTION__, func_get_args(), $directory, compact('directory')); } - public function url($path) - { - return $this->withSentry(__FUNCTION__, func_get_args(), $path, compact('path')); - } - public function __call($name, $arguments) { return $this->filesystem->{$name}(...$arguments); diff --git a/src/Sentry/Laravel/Features/Storage/SentryCloudFilesystem.php b/src/Sentry/Laravel/Features/Storage/SentryCloudFilesystem.php index d9e38095..dacd9c5d 100644 --- a/src/Sentry/Laravel/Features/Storage/SentryCloudFilesystem.php +++ b/src/Sentry/Laravel/Features/Storage/SentryCloudFilesystem.php @@ -4,6 +4,15 @@ use Illuminate\Contracts\Filesystem\Cloud; -class SentryCloudFilesystem extends SentryFilesystem implements Cloud +class SentryCloudFilesystem implements Cloud { + use CloudFilesystemDecorator; + + public function __construct(Cloud $filesystem, array $defaultData, bool $recordSpans, bool $recordBreadcrumbs) + { + $this->filesystem = $filesystem; + $this->defaultData = $defaultData; + $this->recordSpans = $recordSpans; + $this->recordBreadcrumbs = $recordBreadcrumbs; + } } diff --git a/src/Sentry/Laravel/Features/Storage/SentryFilesystemAdapter.php b/src/Sentry/Laravel/Features/Storage/SentryFilesystemAdapter.php index dac830e3..43657000 100644 --- a/src/Sentry/Laravel/Features/Storage/SentryFilesystemAdapter.php +++ b/src/Sentry/Laravel/Features/Storage/SentryFilesystemAdapter.php @@ -6,7 +6,7 @@ class SentryFilesystemAdapter extends FilesystemAdapter { - use FilesystemDecorator; + use FilesystemAdapterDecorator; public function __construct(FilesystemAdapter $filesystem, array $defaultData, bool $recordSpans, bool $recordBreadcrumbs) { diff --git a/src/Sentry/Laravel/Features/Storage/SentryS3V3Adapter.php b/src/Sentry/Laravel/Features/Storage/SentryS3V3Adapter.php index 8403a23e..80bec2ee 100644 --- a/src/Sentry/Laravel/Features/Storage/SentryS3V3Adapter.php +++ b/src/Sentry/Laravel/Features/Storage/SentryS3V3Adapter.php @@ -6,7 +6,7 @@ class SentryS3V3Adapter extends AwsS3V3Adapter { - use FilesystemDecorator; + use FilesystemAdapterDecorator; public function __construct(AwsS3V3Adapter $filesystem, array $defaultData, bool $recordSpans, bool $recordBreadcrumbs) { From 9b3e4dcec8a1e4ff5d6e51e7dd852c6107474006 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Thu, 3 Aug 2023 12:43:27 +0200 Subject: [PATCH 11/11] Test invalid configs throw exception --- .../Features/StorageIntegrationTest.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/Sentry/Features/StorageIntegrationTest.php b/test/Sentry/Features/StorageIntegrationTest.php index 58d2cbf1..e7a5bd7e 100644 --- a/test/Sentry/Features/StorageIntegrationTest.php +++ b/test/Sentry/Features/StorageIntegrationTest.php @@ -162,4 +162,41 @@ public function testDriverWorksWhenDisabled(): void $this->expectNotToPerformAssertions(); } + + public function testThrowsIfDiskConfigurationDoesntSpecifyDiskName(): void + { + $this->resetApplicationWithConfig([ + 'filesystems.disks.local.driver' => 'sentry', + 'filesystems.disks.local.sentry_original_driver' => 'local', + ]); + + $this->expectExceptionMessage('Missing `sentry_disk_name` config key for `sentry` filesystem driver.'); + + Storage::disk('local'); + } + + public function testThrowsIfDiskConfigurationDoesntSpecifyOriginalDriver(): void + { + $this->resetApplicationWithConfig([ + 'filesystems.disks.local.driver' => 'sentry', + 'filesystems.disks.local.sentry_disk_name' => 'local', + ]); + + $this->expectExceptionMessage('Missing `sentry_original_driver` config key for `sentry` filesystem driver.'); + + Storage::disk('local'); + } + + public function testThrowsIfDiskConfigurationCreatesCircularReference(): void + { + $this->resetApplicationWithConfig([ + 'filesystems.disks.local.driver' => 'sentry', + 'filesystems.disks.local.sentry_disk_name' => 'local', + 'filesystems.disks.local.sentry_original_driver' => 'sentry', + ]); + + $this->expectExceptionMessage('`sentry_original_driver` for Sentry storage integration cannot be the `sentry` driver.'); + + Storage::disk('local'); + } }