- How do I install Laravel Nightwatch in my Laravel 11 project?
- Run `composer require laravel/nightwatch` in your project directory. The package auto-registers via its service provider, so no manual configuration is needed in `config/app.php`. Ensure your Laravel version is 10–13 and PHP is 8.1–8.5 for full compatibility.
- What metrics does Laravel Nightwatch collect by default?
- The package captures HTTP request/response times, database queries (with execution time), exceptions, scheduled task performance, and middleware execution. It also tracks authenticated user context and request payloads (unless redacted). Custom metrics can be added via the `Nightwatch::record()` method.
- Can I exclude sensitive routes or data from being sent to Nightwatch?
- Yes. Use the `Nightwatch::ignore()` method to exclude routes or middleware. For sensitive data like API keys or tokens, leverage the built-in redaction system with `Nightwatch::redact('field_name')` or configure global filters in `.env` (e.g., `NIGHTWATCH_REDACT_FIELDS=password,api_key`).
- How does Laravel Nightwatch handle high-traffic production environments?
- The package uses configurable sampling (e.g., `NIGHTWATCH_COMMAND_SAMPLE_RATE=0.1` for 10% sampling) and batching (`NIGHTWATCH_CONCURRENT_REQUESTS=5`) to minimize overhead. For Octane or async workers, ensure your PHP worker pool is sized appropriately, and test under load in staging to validate performance.
- Does Laravel Nightwatch support Laravel Octane (Swoole/RoadRunner)?
- Yes, but with caveats. Octane-specific optimizations (like excluding bootstrapping time) are included, but custom worker setups may require adjustments. Test with your target worker (e.g., Swoole) and monitor for anomalies in metrics like request latency. Use `NIGHTWATCH_OCTANE_OPTIMIZATIONS=true` in `.env` for built-in tweaks.
- How do I correlate metrics with specific users or requests in Nightwatch?
- Nightwatch automatically captures request context, including authenticated user IDs, IP addresses, and session data. For custom context, use `Nightwatch::withContext(['key' => 'value'])` in middleware or services. This data appears in the Nightwatch dashboard for root-cause analysis of performance issues tied to specific users or requests.
- What Laravel versions and PHP versions are officially supported?
- The package officially supports Laravel 10–13 and PHP 8.1–8.5. Laravel 9.x may work with minor configuration tweaks, but it’s untested. PHP 8.0 might require adjustments due to deprecated features. Always check the [official docs](https://nightwatch.laravel.com/docs) for updates.
- Can I self-host Nightwatch instead of using the SaaS platform?
- The core package is open-source (MIT-licensed), but self-hosting the backend is undocumented and unsupported. The SaaS platform handles storage, processing, and alerting. If self-hosting is critical, evaluate alternatives like Laravel Scout or third-party monitoring tools with open APIs.
- How do I test Laravel Nightwatch locally before deploying to production?
- Use the `NIGHTWATCH_ENVIRONMENT=local` setting in `.env` to disable metric collection in development. For staging, enable sampling (e.g., `NIGHTWATCH_COMMAND_SAMPLE_RATE=1.0`) and test with realistic traffic. The package includes Artisan commands like `nightwatch:digest` to manually trigger metric processing for validation.
- Are there alternatives to Laravel Nightwatch for Laravel monitoring?
- Yes. For open-source options, consider Laravel Telescope (debugging-focused) or Prometheus + Grafana (self-hosted). SaaS alternatives include ScoutAPM, Datadog, or New Relic, which offer broader language support but may lack Laravel-specific optimizations. Nightwatch stands out for its deep Laravel integration and simplicity.