Start free trial
Start free trial Log in

14-day free trial. No credit card.

Monitoring Laravel Vapor

Vapor runs on AWS Lambda, so a monitoring agent can't live inside the function.

  • Guide
  • 4 min read

How do I monitor a Laravel Vapor app?

Vapor runs on AWS Lambda, so any long-running agent has to live on a separate host. Pick: (1) Laravel Nightwatch or NightOwl, both with the agent on an EC2 or Forge server in the same VPC and the Vapor app sending telemetry to it, (2) Sentry (an HTTP-based SDK that works inside Lambda), (3) ship CloudWatch logs to a log aggregator for log-level visibility. Track cold starts separately from warm requests, because they tell different stories.

Updated

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:

  1. 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.
  2. 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.
  3. 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
<?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:

text
Lambda logs
   ↓
CloudWatch Logs
   ↓  (subscription filter)
Kinesis Data Firehose / Lambda forwarder
   ↓
Axiom / Loki / Papertrail / S3 + Athena

Better 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

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

Terminal
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.

Keep Vapor and run the agent next to it

Point NIGHTOWL_INGEST_URI at an agent on an EC2 or Forge host in the same VPC, and NightOwl shows your Vapor requests and queued jobs with the queries and exceptions behind them. The price stays flat from $5 a month, however many Lambda invocations you serve.

No credit card needed.

Frequently asked questions

Anything else, write to support@usenightowl.com

How is monitoring Laravel Vapor different from a traditional Laravel app?

Vapor runs your Laravel app on AWS Lambda. That changes three things for monitoring: (1) no persistent worker process to run an agent daemon in, (2) cold starts add variable latency that can dominate p95 on low-traffic routes, (3) CloudWatch is the default log destination and costs add up fast. APMs built around a long-running agent need that agent on a separate host that the Lambda functions send to. The other options are vendor SDKs that ship from within the Lambda, or streaming logs out via CloudWatch to your sink.

Can I use NightOwl with Laravel Vapor?

Yes. The NightOwl agent is a long-running process with a local buffer, so it can't run inside a Lambda invocation. Run it on a long-running server in the same private network (an EC2 instance in the same VPC, or a Forge server peered into it) and set NIGHTOWL_INGEST_URI on the Vapor environment to that host's private address and port. The Vapor app only sends telemetry over TCP and needs no database credentials; the agent host buffers it and writes to your PostgreSQL. Laravel Nightwatch uses the same two-host setup on Vapor. Setup steps: docs.usenightowl.com/agent/vapor.

How do I track Vapor cold starts?

Write a marker file to /tmp on the first request a Lambda container handles. /tmp survives between warm invocations of the same container, so a missing marker means a cold start. A static PHP flag doesn't work, because under Vapor's default PHP-FPM runtime each request starts with fresh PHP state and the flag always reads as a cold start. Record the result alongside the route and duration so you can split p95 into cold-path and warm-path buckets, because they tell very different stories.

How do I monitor Vapor queues?

Vapor uses SQS under the hood and runs queue workers as Lambda functions triggered by SQS events. AWS CloudWatch surfaces queue depth and age-of-oldest-message. For per-job-class tracking (duration, failed attempts, retries) the instrumentation has to run inside the Lambda. The laravel/nightwatch package does this for both Nightwatch and NightOwl, sending each job attempt to an agent on a separate host; other APMs depend on SDK support.

What about Vapor scheduled tasks?

Vapor runs the Laravel scheduler via AWS EventBridge. Don't count on CloudWatch for scheduler output. For structured monitoring (duration and outcome of every run) wire up an APM. Or manually: attach ->onSuccess() and ->onFailure() to each scheduled task in routes/console.php and push metrics to CloudWatch or your APM.

Do Lambda limits affect Vapor monitoring?

Yes. HTTP requests time out after 10 seconds by default (30 seconds at most), and queue and CLI functions stop at Lambda's 15-minute ceiling regardless of code. Lambda's synchronous response payload limit is 6 MB, so big exports need presigned S3 URLs, not direct responses. Memory is bounded per function (up to 10GB). Monitor for Lambda errors like 'Task timed out after 900 seconds'. Those are function crashes, not slow requests.

How do I aggregate Vapor CloudWatch logs?

CloudWatch log groups per Lambda function. Options: (1) keep logs in CloudWatch and search via CloudWatch Insights (expensive at scale), (2) subscribe a Kinesis stream and ship to Loki / Axiom / Papertrail, (3) use a log-aggregator's CloudWatch integration.

Flat pricing, whatever your traffic does

Every plan starts with a 14-day free trial. No credit card needed.

Hobby
$5 a month

One app for a side project. Issues and alerts, with a 14-day dashboard window.

Start my 14-day trial
TeamRecommended
$15 a month

Up to 3 apps and 5 people per team. Full history, the MCP server, data clearing and agent health.

Start my 14-day trial
Agency
$69 a month

Unlimited client apps and people, one overview of every app, and apps you can hand over.

Start my 14-day trial

Related guides

Related

Monitor your Vapor app from one agent host

Stand up one agent host in your VPC and your Vapor requests and jobs land in your own PostgreSQL. No credit card needed.