Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
Send Nightwatch only slow queries from jobs, commands and scheduled tasks (#486)
Paulo Castellano9192fd4b8579
diff --git a/.env.example b/.env.exampleindex a3aea48c6..880ef919a 100644--- a/.env.example+++ b/.env.example@@ -273,6 +273,8 @@ STRIPE_WORKSPACES_YEARLY=# Laravel Nightwatch (production telemetry — disabled by default in dev)NIGHTWATCH_ENABLED=falseNIGHTWATCH_TOKEN=+# Jobs, commands and scheduled tasks send only queries at least this slow (ms)+# NIGHTWATCH_SLOW_QUERY_MS=500# Platform feature flags (all default to true; set to false to hide a platform)# TIKTOK_ENABLED=truediff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.phpindex c459d837c..ca40bdd4b 100644--- a/app/Providers/AppServiceProvider.php+++ b/app/Providers/AppServiceProvider.php@@ -60,7 +60,7 @@ use Illuminate\Support\ServiceProvider;use Illuminate\Validation\Rules\Password;use Laravel\Cashier\Cashier;use Laravel\Nightwatch\Facades\Nightwatch;-use Laravel\Nightwatch\Records\CacheEvent;+use Laravel\Nightwatch\Records\Query;use Laravel\Socialite\Facades\Socialite;use Laravel\Socialite\Two\GoogleProvider;use PostHog\PostHog;@@ -91,6 +91,7 @@ class AppServiceProvider extends ServiceProvider{$this->configureDefaults();$this->configureMorphMap();+ $this->configureNightwatch();$this->configurePostHog();$this->configureRateLimiting();$this->configureSocialite();@@ -101,6 +102,23 @@ class AppServiceProvider extends ServiceProviderCashier::keepPastDueSubscriptionsActive();}+ /**+ * Jobs, commands and scheduled tasks send only their slow queries: the queue+ * runs millions of fast ones a month, and each would count as an event. Web+ * requests keep every query, since they are already sampled.+ */+ protected function configureNightwatch(): void+ {+ if (! config('nightwatch.enabled')) {+ return;+ }++ $slowQueryMicroseconds = config('nightwatch.filtering.slow_query_ms') * 1000;++ Nightwatch::rejectQueries(fn (Query $query): bool => $this->app->runningInConsole()+ && $query->duration < $slowQueryMicroseconds);+ }+protected function configureMorphMap(): void{Relation::enforceMorphMap([@@ -278,14 +296,6 @@ class AppServiceProvider extends ServiceProviderPassword::defaults(fn (): Password => PasswordRequirements::rule());- Nightwatch::rejectCacheEvents(function (CacheEvent $cacheEvent) {- return in_array($cacheEvent->key, [- 'illuminate:foundation:down',- 'illuminate:queue:restart',- 'illuminate:schedule:interrupt',- ]);- });-// Custom email verification templateVerifyEmail::toMailUsing(function (User $user, string $url) {return (new MailMessage)diff --git a/composer.json b/composer.jsonindex d4c100b20..216b40141 100644--- a/composer.json+++ b/composer.json@@ -43,7 +43,7 @@"laravel/framework": "^13.0","laravel/horizon": "^5.45","laravel/mcp": "^1.1",- "laravel/nightwatch": "^1.22",+ "laravel/nightwatch": "^1.30.6","laravel/passport": "^13.7","laravel/reverb": "^1.0","laravel/socialite": "^5.24",diff --git a/composer.lock b/composer.lockindex 3c8f3e144..50573ae63 100644--- a/composer.lock+++ b/composer.lock@@ -4,7 +4,7 @@"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies","This file is @generated automatically"],- "content-hash": "03ab80c010a4fa91c4de382f6572bbff",+ "content-hash": "05783f339378d5195d0e90080f8b9514","packages": [{"name": "aws/aws-crt-php",@@ -2612,21 +2612,21 @@},{"name": "laravel/nightwatch",- "version": "v1.28.0",+ "version": "v1.30.6","source": {"type": "git","url": "https://github.com/laravel/nightwatch.git",- "reference": "229f082a5a4d760e4057c3acc1045ecec7e795bc"+ "reference": "33000668ae9407d204d5033f39cdfe14de4ac161"},"dist": {"type": "zip",- "url": "https://api.github.com/repos/laravel/nightwatch/zipball/229f082a5a4d760e4057c3acc1045ecec7e795bc",- "reference": "229f082a5a4d760e4057c3acc1045ecec7e795bc",+ "url": "https://api.github.com/repos/laravel/nightwatch/zipball/33000668ae9407d204d5033f39cdfe14de4ac161",+ "reference": "33000668ae9407d204d5033f39cdfe14de4ac161","shasum": ""},"require": {"ext-zlib": "*",- "guzzlehttp/promises": "^2.0",+ "guzzlehttp/promises": "^2.0|^3.0","laravel/framework": "^10.0|^11.0|^12.0|^13.0","monolog/monolog": "^3.6","nesbot/carbon": "^2.0|^3.0",@@ -2642,8 +2642,8 @@"aws/aws-sdk-php": "^3.349","ext-pcntl": "*","ext-pdo": "*",- "guzzlehttp/guzzle": "^7.0",- "guzzlehttp/psr7": "^2.0",+ "guzzlehttp/guzzle": "^7.0|^8.0",+ "guzzlehttp/psr7": "^2.0|^3.0","laravel/horizon": "^5.4","laravel/pint": "1.21.0","laravel/vapor-core": "^2.38.2",@@ -2702,7 +2702,7 @@"issues": "https://github.com/laravel/nightwatch/issues","source": "https://github.com/laravel/nightwatch"},- "time": "2026-06-04T01:32:56+00:00"+ "time": "2026-10-27T00:46:16+00:00"},{"name": "laravel/passport",diff --git a/config/nightwatch.php b/config/nightwatch.phpnew file mode 100644index 000000000..79977a791--- /dev/null+++ b/config/nightwatch.php@@ -0,0 +1,38 @@+<?php++declare(strict_types=1);++return [+ 'enabled' => env('NIGHTWATCH_ENABLED', true),+ 'token' => env('NIGHTWATCH_TOKEN'),+ 'deployment' => env('NIGHTWATCH_DEPLOY', env('LARAVEL_CLOUD_DEPLOY_UUID', env('FORGE_DEPLOY_COMMIT', env('VAPOR_COMMIT_HASH')))),+ 'server' => env('NIGHTWATCH_SERVER'),+ 'capture_exception_source_code' => env('NIGHTWATCH_CAPTURE_EXCEPTION_SOURCE_CODE', true),+ 'capture_request_payload' => env('NIGHTWATCH_CAPTURE_REQUEST_PAYLOAD', false),+ 'redact_payload_fields' => explode(',', env('NIGHTWATCH_REDACT_PAYLOAD_FIELDS', '_token,password,password_confirmation')),+ 'redact_headers' => explode(',', env('NIGHTWATCH_REDACT_HEADERS', 'Authorization,Cookie,Proxy-Authorization,X-XSRF-TOKEN')),++ 'sampling' => [+ 'requests' => env('NIGHTWATCH_REQUEST_SAMPLE_RATE', 1.0),+ 'commands' => env('NIGHTWATCH_COMMAND_SAMPLE_RATE', 1.0),+ 'exceptions' => env('NIGHTWATCH_EXCEPTION_SAMPLE_RATE', 1.0),+ 'scheduled_tasks' => env('NIGHTWATCH_SCHEDULED_TASK_SAMPLE_RATE', 1.0),+ ],++ 'filtering' => [+ 'ignore_cache_events' => env('NIGHTWATCH_IGNORE_CACHE_EVENTS', true),+ 'ignore_mail' => env('NIGHTWATCH_IGNORE_MAIL', false),+ 'ignore_notifications' => env('NIGHTWATCH_IGNORE_NOTIFICATIONS', false),+ 'ignore_outgoing_requests' => env('NIGHTWATCH_IGNORE_OUTGOING_REQUESTS', false),+ 'ignore_queries' => env('NIGHTWATCH_IGNORE_QUERIES', false),+ 'slow_query_ms' => (int) env('NIGHTWATCH_SLOW_QUERY_MS', 500),+ 'log_level' => env('NIGHTWATCH_LOG_LEVEL', env('LOG_LEVEL', 'debug')),+ ],++ 'ingest' => [+ 'uri' => env('NIGHTWATCH_INGEST_URI', '127.0.0.1:2407'),+ 'timeout' => env('NIGHTWATCH_INGEST_TIMEOUT', 0.5),+ 'connection_timeout' => env('NIGHTWATCH_INGEST_CONNECTION_TIMEOUT', 0.5),+ 'event_buffer' => env('NIGHTWATCH_INGEST_EVENT_BUFFER', 500),+ ],+];