Announced at Laracon AU 2018, and released shortly therafter, Laravel Telescope is an elegant debugging assistant for the Laravel Framework, improving upon functionality available in Laravel Debugbar.
I won't talk much about Telescope here, but you can learn more from this post on Matt Stauffer's blog.
Whilst its primary purpose is as a debugging tool in development, it is also a powerful asset in debugging your production environment. In order to get Telescope, however, I ran in to some stumbling points in my CI environment in GitLab.
To work around this, I set out to conditionally load Telescope. I stumbled upon this comment from Mohamed Said, which suggested loading the TelescopeServiceProvider
in one of your application's service providers, but doing so was not enough.
Telescope leverages package auto-discovery to load its default package provider, but in order to prevent this for certain environments (build
, testing
), we need to opt-out by including laravel/telescope
in the composer.json
file's extra.laravel.dont-discover
key.
"extra": {
"laravel": {
"dont-discover": [
"laravel/telescope"
]
}
}
The default telescope:install
command will also place an entry in config/app.php
, which is used for application-specific configuration of Telescope, such as authorising access in non-local environments and enabling dark mode.
In order to fully control which conditions Telescope is loaded under, we must also remove the App\Providers\TelescopeServiceProvider::class
entry from the providers
array.
Now, in your AppServiceProvider
's register
method, we can add the following:
if (! $this->app->environment('build', 'testing')) {
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
$this->app->register(TelescopeServiceProvider::class);
}
This ensures that both the default Telescope registration, which would have been handled by package auto-discovery, occurs as well as any application-specific configuration in App\Providers\TelescopeServiceProvider
.