Serverless quietly breaks most of what you assume about monitoring a Laravel app. You can't SSH into a box, and the function has no long-running process to attach an agent to. Every request is a fresh (or recently-thawed) Lambda, and the cold ones can be several times slower than the warm ones for reasons that have nothing to do with your code. The tools and habits that work on Forge or a VPS mostly don't transfer, so it's worth being deliberate about what you actually watch on Vapor.
Why Vapor is different
Each request runs in a Lambda function. Three meaningful consequences for monitoring:
- No persistent process. On a server, an agent daemon runs next to PHP-FPM or Octane for as long as the machine is up. Lambda's execution model assumes the function returns and its memory goes away, and the next invocation starts fresh or reuses a warm container. An agent daemon has to run on a separate, long-running host.
- Cold starts can dominate p95. A Lambda cold start on PHP can add hundreds of milliseconds or more, depending on package and layer size. A route that looks slow at p95 might be 95% fast + 5% cold-starting, which is a very different bug than being uniformly slow.
- CloudWatch is the default. All stdout/stderr ends up in CloudWatch Logs. Powerful but expensive at scale; queries (CloudWatch Insights) cost per GB scanned.
Tracking cold starts
Detect cold starts by checking whether a Lambda container is handling its first request. A static property won't do it: under Vapor's default PHP-FPM runtime each request starts with fresh PHP state, so it would report every request as cold. A marker file in /tmp survives between warm invocations of the same container. Record the result alongside route and duration:
app/Http/Middleware/TrackColdStart.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class TrackColdStart
{
public function handle(Request $request, Closure $next)
{
$marker = '/tmp/container-warm';
$isColdStart = ! file_exists($marker);
if ($isColdStart) {
touch($marker);
}
$request->attributes->set('is_cold_start', $isColdStart);
return $next($request);
}
}
Push is_cold_start to your telemetry. Split p95 by cold vs warm: a slow cold path is a bundle-size problem (shrink the deployment package); a slow warm path is a code or database problem.
CloudWatch → log aggregator
Raw CloudWatch gets expensive for search. Stream logs out via a subscription:
Lambda logs
↓
CloudWatch Logs
↓ (subscription filter)
Kinesis Data Firehose / Lambda forwarder
↓
Axiom / Loki / Papertrail / S3 + AthenaBetter Stack, Axiom, and Papertrail all have AWS CloudWatch integrations. Or run a small Lambda forwarder that ships logs to your own Loki or OpenSearch.
Queue monitoring
Vapor queues are SQS + Lambda consumers. Key metrics:
- ApproximateAgeOfOldestMessage: SQS metric, surfaces queue lag
- ApproximateNumberOfMessagesVisible: queue depth
- Lambda Errors / Throttles: job failures / concurrency limit hit
- Lambda Duration: per-job runtime
All visible in CloudWatch metrics. Alert on rising age-of-oldest or throttle rate.
Scheduled tasks
Vapor's scheduler runs via an EventBridge rule that invokes Lambda. Scheduler output doesn't reliably show up in CloudWatch, so hook each task directly:
routes/console.php
use Illuminate\Support\Facades\Schedule;
Schedule::command('reports:send')
->daily()
->onSuccess(function () {
// push a metric
})
->onFailure(function () {
// push a metric and alert
});Vapor-compatible APM options
- Laravel Nightwatch: first-party Laravel APM. Its agent can't run inside the Vapor app, so it runs on a separate EC2 or Forge server that the app sends to
- NightOwl: the same two-host setup as Nightwatch, with the data in your own PostgreSQL (see below)
- Sentry: HTTP-based SDK, Lambda-safe. Tracks errors + performance spans
- Datadog APM: PHP isn't an officially supported runtime for Datadog's Lambda tracing, so check before you plan on it
Running NightOwl on Vapor
The NightOwl agent is a long-running daemon with a local SQLite buffer, so it runs next to Vapor, not inside it. Stand up a persistent server that can reach your PostgreSQL and that your Vapor environment can route to (an EC2 instance in the same VPC, or a Forge server peered into it). Deploy the same application release there and run php artisan nightowl:agent under a supervisor, with NIGHTOWL_AGENT_HOST=0.0.0.0, your NIGHTOWL_TOKEN, and your NIGHTOWL_DB_* credentials. Allow inbound TCP on port 2407 from your Vapor subnet only. Then point the Vapor environment at the agent host's private address:
Vapor environment variables
NIGHTOWL_INGEST_URI=10.0.0.5:2407 # the agent host's private address
NIGHTOWL_INGEST_TIMEOUT=1.0
NIGHTOWL_TOKEN=your-agent-token # the same token the agent host verifies
The Vapor app needs no NIGHTOWL_DB_* variables: it only sends telemetry over TCP, and only the agent host writes to your database. Deploy the same release to both sides so they agree on the laravel/nightwatch wire format. Keep port 2407 and the health port (2409) closed to the public internet. The full walkthrough is in the Vapor guide in the NightOwl docs.