webrek/laravel-telescope-mongodb
Drop-in MongoDB storage driver for Laravel Telescope. Run Telescope without MySQL/PostgreSQL: install via artisan, publishes assets, removes SQL migrations, creates required MongoDB indexes, and binds the repository. Includes command to migrate existing SQL Telescope data.
Installation:
composer require webrek/laravel-telescope-mongodb
php artisan telescope-mongodb:install
EntriesRepository.First Use Case:
/telescope in your browser. The dashboard will now populate with:
Prerequisites Check:
jenssegers/laravel-mongodb is installed (this package depends on it).config/database.php has a MongoDB connection configured (e.g., mongodb).Replacing SQL with MongoDB:
telescope_entries table is replaced by a MongoDB collection (telescope_entries by default).type (e.g., request, exception).created_at (for time-based queries).tags (for filtering).type + id).Integrating with Existing Telescope:
EntriesRepository.TelescopeServiceProvider is registered in config/app.php (handled by the installer)..env:
TELESCOPE_ENABLED=true
TELESCOPE_DATABASE=mongodb
Querying Data:
@telescope) or API endpoints (/telescope/entries).$entries = Telescope::entries()
->where('type', 'exception')
->where('tags', 'auth')
->orderBy('created_at', 'desc')
->get();
limit() calls without skip()—MongoDB’s cursor behavior differs from SQL.Customizing Collections:
config/telescope.php:
'mongodb' => [
'collection' => 'custom_telescope_entries',
],
Handling Large Datasets:
Schema::connection('mongodb')->collection('telescope_entries')->createIndex(
['created_at' => 1],
['expireAfterSeconds' => 2592000] // 30 days
);
aggregate() to archive data to a separate collection:
$archive = Telescope::entries()
->match(['created_at' => ['$lt' => now()->subDays(90)]])
->aggregate([['$out' => 'telescope_archive']]);
Missing Indexes:
php artisan telescope-mongodb:install or manually create the 7 required indexes:
Schema::connection('mongodb')->collection('telescope_entries')->createIndex('type');
Schema::connection('mongodb')->collection('telescope_entries')->createIndex('created_at');
// ... (repeat for all 7 indexes listed in the package's docs).
Schema Changes:
Memory Usage:
allowDiskUse(true) in aggregation queries.Timezone Handling:
created_at as UTC by default, but Telescope may display it in the app’s timezone.config/app.php has consistent timezone settings and Telescope’s created_at is formatted correctly in Blade:
{{ $entry->created_at->tz('UTC')->format('Y-m-d H:i:s') }}
Concurrent Writes:
insertOne with ordered: false in the driver’s write operations (if customizing the package).Check MongoDB Logs:
db.setProfilingLevel(1, { slowms: 50 });
db.system.profile.find().sort({ ts: -1 }).limit(10);
Verify Index Usage:
db.telescope_entries.aggregate([{ $indexStats: {} }]);
Test Locally:
TELESCOPE_ENABLED=false in production until fully tested. MongoDB’s performance characteristics (e.g., indexing) may differ from SQL.Custom Entry Types:
// config/telescope-mongodb.php
'custom_indexes' => [
'custom_type_1' => ['field1', 'field2'],
];
Overriding the Driver:
EntriesRepository:
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->bind(
\Laravel\Telescope\EntriesRepository::class,
\Webrek\TelescopeMongoDB\Repositories\CustomEntriesRepository::class
);
}
Adding Fields to Entries:
user_id), extend the TelescopeEntry model:
namespace App\Models;
use Webrek\TelescopeMongoDB\Models\TelescopeEntry as BaseEntry;
class TelescopeEntry extends BaseEntry
{
protected $casts = [
'user_id' => 'integer',
];
}
API Extensions:
Route::middleware(['web', 'telescope'])
->get('/telescope/custom-query', function () {
return Telescope::entries()
->match(['tags' => 'api'])
->project(['method', 'path', 'duration'])
->toArray();
});
How can I help you explore Laravel packages today?