-
-
Notifications
You must be signed in to change notification settings - Fork 202
Improve storage integration #750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve storage integration #750
Conversation
# Conflicts: # CHANGELOG.md # src/Sentry/Laravel/Features/Storage/Integration.php
|
Thanks for the updates @stayallive. The new inheritance/implementation structure makes sense to me. |
# Conflicts: # CHANGELOG.md
| private function registerDiskDriver(): void | ||
| protected function registerDriver(): void | ||
| { | ||
| $this->container()->afterResolving(FilesystemManager::class, function (FilesystemManager $filesystemManager): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this line of code was written by you in the previous PR, I think it is not a good idea to extend the filesystemManager call when afterResolving it.
This is because the FilesystemManager class may be resolved before the SentryServiceProvider, and therefore, the callback will never be called.
| $this->container()->afterResolving(FilesystemManager::class, function (FilesystemManager $filesystemManager): void { | |
| $callback = function (FilesystemManager $filesystemManager): void { | |
| $filesystemManager->extend(self::STORAGE_DRIVER_NAME, function (Application $application, array $config) use ($filesystemManager): Filesystem { | |
| //... | |
| }); | |
| }; | |
| if ($this->container()->resolved(FilesystemManager::class)) { | |
| $callback($this->container()->get(FilesystemManager::class)); | |
| } else { | |
| $this->container()->afterResolving(FilesystemManager::class, $callback); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should never happen. We register in the register callback of a service provider. And resolving should have never happened there so this should be perfectly fine unless somethin wonky is going on. Do you have a specific use case in mind where this would actually fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it actually happend in our project, but I need time to reproduce in a simple Laravel project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you have a service provider that is not well behaved, meaning that it does more than just register bindings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you register the Sentry service provider manually and from inside another service provider, but we use the afterResolving callback on more places and I've never seen the issues you describe or heard people having them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, we have a service provider that calls $this->app->make('filesystem') in the boot method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, we are doing this in the boot not register. I'll see what we can do to change that. But your suggestion wouldn't currently fix the problem since it will still be too late, but I see where the problem is.
Edit: working on solution here #759.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yankewei it took a bit, but I think we solved the issue and now register the driver before Laravel is booted which should solve the issues you were seeing!
# Conflicts: # src/Sentry/Laravel/Features/Storage/Integration.php
stayallive
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, still easy to enable but a little more "involved" that hopefuly makes people pay atttentiont to see if it works with their code 💪 Thanks all!
This improves upon the storage integration as described in #745 (comment).
I believe extending the existing Laravel classes is valuable. We saw in #745 that users are expecting to receive specific classes instead of the insufficient interfaces.
Requiring users to do manual configuration of their disks is fine, but we can make it easier and less error-prone by offering wrapper methods.
During testing, I found that because the configuration is now static, it is always required to register the
sentrydriver. Otherwise, environments that do not set the DSN fail to access storage withDriver [sentry] is not supported.. First I thought this change was somewhat of a hack, but then realized it is actually a good thing; it means that the errors reported in #745 would now be found in local or testing environments already.Testing in our application went fine, I successfully got the following spans and breadcrumbs: