Skip to content

Commit

Permalink
Add laravel/telescope support (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkons authored Apr 27, 2021
1 parent cad0de8 commit 4a3d70b
Show file tree
Hide file tree
Showing 5 changed files with 4,414 additions and 11 deletions.
189 changes: 189 additions & 0 deletions Configs/telescope.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<?php

use Laravel\Telescope\Http\Middleware\Authorize;
use Laravel\Telescope\Watchers;

return [

/*
|--------------------------------------------------------------------------
| Telescope Theme
|--------------------------------------------------------------------------
|
| Change default Telescope theme to night mode
|
*/
'night_theme' => env('TELESCOPE_NIGHT_THEME', false),

/*
|--------------------------------------------------------------------------
| Telescope Prune data
|--------------------------------------------------------------------------
|
| Determine if Telescope entries must be pruned
|
*/
'prune' => env('TELESCOPE_PRUNE', false),

/*
|--------------------------------------------------------------------------
| Telescope Domain
|--------------------------------------------------------------------------
|
| This is the subdomain where Telescope will be accessible from. If the
| setting is null, Telescope will reside under the same domain as the
| application. Otherwise, this value will be used as the subdomain.
|
*/

'domain' => env('TELESCOPE_DOMAIN', null),

/*
|--------------------------------------------------------------------------
| Telescope Path
|--------------------------------------------------------------------------
|
| This is the URI path where Telescope will be accessible from. Feel free
| to change this path to anything you like. Note that the URI will not
| affect the paths of its internal API that aren't exposed to users.
|
*/

'path' => env('TELESCOPE_PATH', 'telescope'),

/*
|--------------------------------------------------------------------------
| Telescope Storage Driver
|--------------------------------------------------------------------------
|
| This configuration options determines the storage driver that will
| be used to store Telescope's data. In addition, you may set any
| custom options as needed by the particular driver you choose.
|
*/

'driver' => env('TELESCOPE_DRIVER', 'database'),

'storage' => [
'database' => [
'connection' => env('DB_CONNECTION', 'mysql'),
'chunk' => 1000,
],
],

/*
|--------------------------------------------------------------------------
| Telescope Master Switch
|--------------------------------------------------------------------------
|
| This option may be used to disable all Telescope watchers regardless
| of their individual configuration, which simply provides a single
| and convenient way to enable or disable Telescope data storage.
|
*/

'enabled' => env('TELESCOPE_ENABLED', false),

/*
|--------------------------------------------------------------------------
| Telescope Route Middleware
|--------------------------------------------------------------------------
|
| These middleware will be assigned to every Telescope route, giving you
| the chance to add your own middleware to this list or change any of
| the existing middleware. Or, you can simply stick with this list.
|
*/

'middleware' => [
'web',
Authorize::class,
],

/*
|--------------------------------------------------------------------------
| Allowed / Ignored Paths & Commands
|--------------------------------------------------------------------------
|
| The following array lists the URI paths and Artisan commands that will
| not be watched by Telescope. In addition to this list, some Laravel
| commands, like migrations and queue commands, are always ignored.
|
*/

'only_paths' => [
// 'api/*'
],

'ignore_paths' => [
'nova-api*',
],

'ignore_commands' => [
//
],

/*
|--------------------------------------------------------------------------
| Telescope Watchers
|--------------------------------------------------------------------------
|
| The following array lists the "watchers" that will be registered with
| Telescope. The watchers gather the application's profile data when
| a request or task is executed. Feel free to customize this list.
|
*/

'watchers' => [
Watchers\BatchWatcher::class => env('TELESCOPE_BATCH_WATCHER', true),
Watchers\CacheWatcher::class => env('TELESCOPE_CACHE_WATCHER', true),

Watchers\CommandWatcher::class => [
'enabled' => env('TELESCOPE_COMMAND_WATCHER', true),
'ignore' => [],
],

Watchers\DumpWatcher::class => env('TELESCOPE_DUMP_WATCHER', true),

Watchers\EventWatcher::class => [
'enabled' => env('TELESCOPE_EVENT_WATCHER', true),
'ignore' => [],
],

Watchers\ExceptionWatcher::class => env('TELESCOPE_EXCEPTION_WATCHER', true),
Watchers\JobWatcher::class => env('TELESCOPE_JOB_WATCHER', true),
Watchers\LogWatcher::class => env('TELESCOPE_LOG_WATCHER', true),
Watchers\MailWatcher::class => env('TELESCOPE_MAIL_WATCHER', true),

Watchers\ModelWatcher::class => [
'enabled' => env('TELESCOPE_MODEL_WATCHER', true),
'events' => ['eloquent.*'],
'hydrations' => true,
],

Watchers\NotificationWatcher::class => env('TELESCOPE_NOTIFICATION_WATCHER', true),

Watchers\QueryWatcher::class => [
'enabled' => env('TELESCOPE_QUERY_WATCHER', true),
'ignore_packages' => true,
'slow' => 100,
],

Watchers\RedisWatcher::class => env('TELESCOPE_REDIS_WATCHER', true),

Watchers\RequestWatcher::class => [
'enabled' => env('TELESCOPE_REQUEST_WATCHER', true),
'size_limit' => env('TELESCOPE_RESPONSE_SIZE_LIMIT', 64),
],

Watchers\GateWatcher::class => [
'enabled' => env('TELESCOPE_GATE_WATCHER', true),
'ignore_abilities' => [],
'ignore_packages' => true,
],

Watchers\ScheduleWatcher::class => env('TELESCOPE_SCHEDULE_WATCHER', true),

Watchers\ViewWatcher::class => env('TELESCOPE_VIEW_WATCHER', true),
],
];
5 changes: 5 additions & 0 deletions Providers/MainServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public function register(): void
{
parent::register();

if ($this->app->environment('local')) {
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
$this->app->register(TelescopeServiceProvider::class);
}

app(QueryDebuggerTask::class)->run();
}
}
96 changes: 96 additions & 0 deletions Providers/TelescopeServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace App\Containers\Vendor\Debugger\Providers;

use Laravel\Telescope\Telescope;
use Illuminate\Support\Facades\Gate;
use Laravel\Telescope\IncomingEntry;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Console\Scheduling\Schedule;
use Laravel\Telescope\TelescopeApplicationServiceProvider;

class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
parent::boot();

if (!is_dir(public_path('vendor/telescope'))) {
Artisan::call('vendor:publish --tag=telescope-assets');
}

if (config('telescope.prune')) {
$this->app->booted(function () {
$schedule = app(Schedule::class);
$schedule->command('telescope:prune')->daily();
});
}
}

/**
* Register any application services.
*
* @return void
*/
public function register()
{
if (config('telescope.night_theme')) {
Telescope::night();
}

$this->hideSensitiveRequestDetails();

Telescope::filter(function (IncomingEntry $entry) {
if ($this->app->environment('local')) {
return true;
}

return $entry->isReportableException() ||
$entry->isFailedRequest() ||
$entry->isFailedJob() ||
$entry->isScheduledTask() ||
$entry->hasMonitoredTag();
});
}

/**
* Prevent sensitive request details from being logged by Telescope.
*
* @return void
*/
protected function hideSensitiveRequestDetails()
{
if ($this->app->environment('local')) {
return;
}

Telescope::hideRequestParameters(['_token']);

Telescope::hideRequestHeaders([
'cookie',
'x-csrf-token',
'x-xsrf-token',
]);
}

/**
* Register the Telescope gate.
*
* This gate determines who can access Telescope in non-local environments.
*
* @return void
*/
protected function gate()
{
Gate::define('viewTelescope', function ($user) {
return in_array($user->email, [
//
]);
});
}
}
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "apiato/debugger-container",
"description": "An Apiato container which helps to debug requests and queries",
"description": "An Apiato container which helps to debug everything",
"type": "apiato-container",
"license": "MIT",
"require": {
"jenssegers/agent": "^2.6.4"
"jenssegers/agent": "^2.6.4",
"laravel/telescope": "^4.4.9"
},
"require-dev": {
"roave/security-advisories": "dev-latest"
Expand Down
Loading

0 comments on commit 4a3d70b

Please sign in to comment.