Expand description
§Telescope for Laravel Rust
laravel-telescope is a port of laravel/telescope to Laravel Rust. It records the requests coming into your application, their queries, exceptions, log entries, queued jobs and model changes, and shows them in Telescope’s dashboard.
[!NOTE] This is a community port maintained by Rivervo. It is not an official Laravel package. It follows laravel/telescope 5.29.0: the same dashboard (the package’s compiled Vue app, unchanged), the same
telescope-apiJSON endpoints, tables, entry contents, tags, monitored tags, recording toggle andtelescope:*commands, with Rust naming. All credit for the design goes to Taylor Otwell and the package’s contributors.
- Installation
- Configuration
- Dashboard authorization
- Content Security Policy
- Watchers
- Commands
- Differences from PHP
- License
§Installation
cargo add laravel-telescopeRegister the service provider in src/app.rs, then run your migrations:
use laravel_telescope::TelescopeServiceProvider;
Application::configure()
.with_providers(|providers| {
providers.add(TelescopeServiceProvider::new().user::<User>().watch_model::<Post>());
})laravel migrateThe dashboard is at /telescope. Schedule telescope:prune so the tables don’t grow without end:
schedule.command("telescope:prune --hours=48").daily();§Configuration
TelescopeConfig holds config/telescope.php’s settings with the same environment variables: TELESCOPE_ENABLED, TELESCOPE_PATH, one switch per watcher (TELESCOPE_REQUEST_WATCHER, TELESCOPE_QUERY_WATCHER, TELESCOPE_EXCEPTION_WATCHER, TELESCOPE_LOG_WATCHER, TELESCOPE_JOB_WATCHER, TELESCOPE_MODEL_WATCHER) and TELESCOPE_RESPONSE_SIZE_LIMIT. In config/telescope.toml you can also set connection, chunk, only_paths, ignore_paths, ignore_http_methods, ignore_status_codes, slow_query_ms (100) and log_level (error).
The provider has PHP’s Telescope::* settings as methods:
| PHP | Rust |
|---|---|
Telescope::auth() | auth(|request| ...) |
Telescope::cspNonce($nonce) | laravel_telescope::csp_nonce(nonce), for the current request |
Telescope::night() | night() |
Telescope::hideRequestHeaders(), hideRequestParameters(), hideResponseParameters() | hide_request_headers(&[..]), hide_request_parameters(&[..]), hide_response_parameters(&[..]) |
$request->user() on entries | user::<User>() |
ModelWatcher | watch_model::<Post>() per model |
authorization, php-auth-pw and cookie headers and _token, password and password_confirmation parameters are hidden by default, as in PHP.
§Dashboard authorization
As in PHP, the dashboard opens only in the local environment until you say who may open it:
TelescopeServiceProvider::new().auth(|request| {
Box::pin(async move {
let Ok(auth) = laravel::auth::Auth::<User>::of(request).await else { return false };
auth.user().await.ok().flatten().is_some_and(|user| ["taylor@laravel.com"].contains(&user.email.as_str()))
})
})Each application keeps its own callback, so several applications in one process (such as parallel tests) don’t share it.
§Content Security Policy
When the request has a CSP nonce, the dashboard’s <style> and <script> tags and the font stylesheet’s <link> carry it as nonce="...", as Laravel’s Vite helper does for stylesheets. Without one, they have no nonce attribute. The nonce is Laravel Rust’s per-request laravel::view::csp_nonce(), which laravel-csp’s middleware sets. With another CSP middleware, set it with laravel::view::use_csp_nonce(..) or with PHP’s Telescope::cspNonce():
laravel_telescope::csp_nonce(&nonce); // for the current requestThe nonce alone isn’t enough for a strict policy. As in PHP, the dashboard’s Vue app compiles its templates in the browser, which needs 'unsafe-eval' in script-src, and the page loads the Figtree font from fonts.bunny.net (font-src; the stylesheet itself carries the nonce). Its favicon is a data: image, and entries show Gravatar images from www.gravatar.com (img-src).
§Watchers
| Watcher | Records |
|---|---|
| Requests | every request outside the dashboard and ignore_paths: method, URI, headers, payload, session, response status, headers and body, duration and the logged-in user |
| Queries | every query with its SQL, connection, time, slow tag and source line |
| Exceptions | every reported error with its class, message, location, code around the line and the number of occurrences; the dashboard marks them resolved |
| Logs | tracing events at or above log_level, with their fields as context |
| Jobs | each processed or failed job, with its queue, connection, attempt and error |
| Models | created, updated (with the changes) and deleted of the models you watch |
Entries are grouped per request or job and stored together when it finishes, as PHP’s batches. laravel_telescope::record(IncomingEntry::make(..)) records your own entries.
§Commands
laravel telescope:list request --limit=10
laravel telescope:show latest:exception
laravel telescope:prune --hours=24 --keep-exceptions
laravel telescope:clear
laravel telescope:pause
laravel telescope:resume§Differences from PHP
- The dashboard has every screen, but Laravel Rust has no hooks yet for the mail, notification, cache, Redis, view, gate, event, HTTP client, dump, command, schedule and batch watchers, so those screens stay empty. The request, query, exception, log, job and model watchers record as in PHP.
- Laravel Rust shows query listeners bound values only when a query binds them with
bind_visible, so the recorded SQL keeps other values as placeholders. - Request entries have no
controller_action,middlewareormemory; a job entry is recorded when the job finishes, so it isn’tpendingfirst, and has nodataortimeout. - Exceptions have the error’s causes in place of PHP’s stack trace.
- Models are watched one by one with
watch_model::<M>(), since Laravel Rust has no global model events. - The dashboard’s time zone is UTC: Laravel Rust has no
app.timezone.Telescope::filter(),tag(),avatar()and$domainaren’t offered.
§License
MIT. See LICENSE.md.
Modules§
- entry_
type - The types of entries:
EntryType.
Structs§
- Authorize
Authorize: a403unlesscheckallows the request.- Entries
Repository - The entries store:
DatabaseEntriesRepository. - Entry
Query Options - The filters of the dashboard’s lists:
EntryQueryOptions. - Entry
Result - An entry as the dashboard reads it:
EntryResult. - Incoming
Entry - An entry to store:
IncomingEntry. - LogWatcher
LogWatcher: atracinglayer that records log events at or above the configured level.- Record
Requests - Records each request and stores the request’s entries afterwards:
RequestWatcherandTelescope::store()onterminating. Added as global middleware. - Remember
Request User - Remembers the request’s user and session for its entries. Added to the
webgroup. - Telescope
Config - The package’s settings:
config/telescope.php, with the same environment variables and defaults. Each watcher has its switch and options. - Telescope
Service Provider - Registers the
TelescopeConfigsection, the migration, the watchers, the dashboard and thetelescope:*commands:
Functions§
- check
Telescope::check(): theauth()callback, or only in thelocalenvironment.- csp_
nonce Telescope::cspNonce(): sets the Content Security Policy nonce that the dashboard’s<style>,<script>and stylesheet<link>tags carry, for the current request.- is_
recording - Whether Telescope records:
Telescope::isRecording(). A request reads the pause from the cache when it starts, as PHP’sTelescope::start()does. - record
- Records an entry in the current batch:
Telescope::record().
Type Aliases§
- Auth
Using - Decides who may open the dashboard:
Telescope::auth().