Skip to main content

Crate laravel_telescope

Crate laravel_telescope 

Source
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-api JSON endpoints, tables, entry contents, tags, monitored tags, recording toggle and telescope:* commands, with Rust naming. All credit for the design goes to Taylor Otwell and the package’s contributors.

§Installation

cargo add laravel-telescope

Register 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 migrate

The 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:

PHPRust
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 entriesuser::<User>()
ModelWatcherwatch_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 request

The 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

WatcherRecords
Requestsevery request outside the dashboard and ignore_paths: method, URI, headers, payload, session, response status, headers and body, duration and the logged-in user
Queriesevery query with its SQL, connection, time, slow tag and source line
Exceptionsevery reported error with its class, message, location, code around the line and the number of occurrences; the dashboard marks them resolved
Logstracing events at or above log_level, with their fields as context
Jobseach processed or failed job, with its queue, connection, attempt and error
Modelscreated, 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, middleware or memory; a job entry is recorded when the job finishes, so it isn’t pending first, and has no data or timeout.
  • 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 $domain aren’t offered.

§License

MIT. See LICENSE.md.

Modules§

entry_type
The types of entries: EntryType.

Structs§

Authorize
Authorize: a 403 unless check allows the request.
EntriesRepository
The entries store: DatabaseEntriesRepository.
EntryQueryOptions
The filters of the dashboard’s lists: EntryQueryOptions.
EntryResult
An entry as the dashboard reads it: EntryResult.
IncomingEntry
An entry to store: IncomingEntry.
LogWatcher
LogWatcher: a tracing layer that records log events at or above the configured level.
RecordRequests
Records each request and stores the request’s entries afterwards: RequestWatcher and Telescope::store() on terminating. Added as global middleware.
RememberRequestUser
Remembers the request’s user and session for its entries. Added to the web group.
TelescopeConfig
The package’s settings: config/telescope.php, with the same environment variables and defaults. Each watcher has its switch and options.
TelescopeServiceProvider
Registers the TelescopeConfig section, the migration, the watchers, the dashboard and the telescope:* commands:

Functions§

check
Telescope::check(): the auth() callback, or only in the local environment.
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’s Telescope::start() does.
record
Records an entry in the current batch: Telescope::record().

Type Aliases§

AuthUsing
Decides who may open the dashboard: Telescope::auth().