Laravel Pulse
repository·1.x·Indexed 23 days ago
https://github.com/laravel/pulseA real-time application performance monitoring (APM) tool and dashboard for Laravel applications. It provides visibility into application health and performance metrics, featuring CLI commands for data processing (pulse:work), snapshots (pulse:check), and data management (pulse:clear, pulse:restart). The tool allows for custom data recording via the Entry class, configurable ingest drivers (storage, redis, null), and customizable system metric detection for CPU and memory.
What's inside Laravel Pulse
- Laravel Pulse is a real-time application performance monitoring tool and dashboard designed specifically for Laravel applications. It allows you to monitor your application's health, performance, and usage metrics through a dedicated dashboard.
Migrate from Pulse Beta to 1.x
1.xWhen upgrading from a Beta version of Laravel Pulse to version 1.x, several breaking changes and architectural shifts occurred. Ensure you address the following:
- SQL Highlighting: Configuration for SQL highlighting has moved to the dashboard component. If you previously disabled SQL highlighting via configuration, you must now manage this through the dashboard component.
- Database Schema (IDs): Pulse tables now include auto-incrementing IDs. This is necessary for environments like PlanetScale that require a unique key on every table.
- Database Schema (Column Types):
TEXTcolumns inpulse_tables have been upgraded toMEDIUMTEXTto support longer content, such as extensive SQL queries. - Migration Ownership: Pulse migrations are now published directly to your application. This allows for full control over the migration lifecycle.
- Command Behavior: The
pulse:checkcommand now dispatches events approximately every second. If you are performing work on specific intervals within this command, it is recommended to use the newthrottlefunction to manage execution frequency.
Configure Pulse authorization
1.xBy default, Pulse uses a Gate named
viewPulseto authorize access to the dashboard. In the default service provider implementation, this gate is defined to returntrueonly when the application environment islocal.You can customize this authorization logic in your own
AuthServiceProviderby defining theviewPulsegate.Publish Pulse configuration, views, and migrations
1.xTo customize Pulse, you can publish its configuration, dashboard views, and database migrations using the following Artisan commands:
Publish Configuration:
php artisan vendor:publish --tag=pulse-configPublish Dashboard Views:
php artisan vendor:publish --tag=pulse-dashboardPublish Migrations:
php artisan vendor:publish --tag=pulse-migrationsConfigure Exception Recorder location
1.xThe Exceptions recorder can optionally include the file location (file path and line number) in its recorded data. This is controlled via thepulse.recorders.Laravel\Pulse\Recorders\Exceptions.locationconfiguration key. If this key is set totrue, Pulse will attempt to resolve the specific file and line where the exception occurred, attempting to skip vendor files to find the relevant application code.Configure Pulse dashboard routing
1.xYou can customize how the Pulse dashboard is accessed via the
config/pulse.phpconfiguration file.path: The URL prefix for the dashboard (e.g.,pulse).domain: An optional domain to restrict the dashboard to.middleware: An array of additional middleware to apply to the Pulse route group.
Configure Pulse ingest drivers
1.xPulse uses ingest drivers to handle how data is collected and stored. You can configure the driver in your
config/pulse.phpfile using theingest.driverkey.Available drivers:
storage: Uses theStorageIngestimplementation.redis: Uses theRedisIngestimplementation.null: Uses theNullIngestimplementation (useful for disabling data collection without disabling Pulse entirely).
Filter items before storage
1.xUse thefilter()method to define a callback that determines whether a specificEntryorValueshould be stored. If the callback returnsfalse, the item is discarded during the ingestion process.Remember a user ID
1.xUserememberUser()to manually set the ID of the user currently being tracked. This is useful in contexts where the standard authentication guard might not be available or when tracking background jobs.Record a value with `set()`
1.xUse the
set()method to log a string-based value (aValue) to Pulse. This is typically used for tracking state or text-based information.Arguments:
type: AUnitEnum,BackedEnum, orstringrepresenting the category.key: AUnitEnum,BackedEnum, orstringrepresenting the specific key.value: Thestringvalue to record.timestamp: An optionalDateTimeInterface,int, ornull(defaults tonow()).
Customize user data displayed in the Pulse dashboard
1.xBy default, Pulse attempts to resolve user information (name, email/extra, and avatar) from your
Authenticatablemodel. If your user model uses different property names or you want to provide custom data, you can usesetFieldResolverto define how user fields are mapped.The resolver callback must return an object with the following structure:
name: (string) The display name of the user.extra: (string, optional) Additional information, typically the email address.avatar: (string, optional) A URL to the user's avatar image.
Configure user resolution for Pulse
1.xPulse needs to know how to map user IDs to user details (name, email, avatar) for the dashboard. Use the
user()method to provide a callback that resolves anAuthenticatableuser into an array of user details.Expected return format:
['name' => '...', 'email' => '...', 'avatar' => '...', 'extra' => '...']