Start free trial
Start free trial Log in

14-day free trial. No credit card.

What is an APM agent?

  • Glossary
  • 3 minute read

What is an APM agent and why does its architecture matter?

An APM agent is the code or process that collects telemetry from your application and ships it to a dashboard. In-process agents run inside your app's runtime. They're simple to install, but overhead hits every request. Out-of-process agents run as separate daemons (like NightOwl's ReactPHP agent), with minimal request-path overhead but slightly more deployment complexity. For production Laravel, out-of-process is the safer default, especially on Octane, where an in-process agent that doesn't reset between requests carries memory across them.

Updated

Most explanations of APM stop at the dashboard. But the part that decides whether monitoring costs you latency, survives a vendor outage, or quietly leaks memory on Octane is the agent, the component that actually sits in or beside your app collecting the data. It's the least glamorous piece and the one whose design you'll feel the most.

Three agent architectures

1. In-process (library)

A composer package that registers inside your Laravel app. Captures telemetry inside the PHP process during the request, then either writes it to storage directly (Telescope writes to your database) or sends it to the vendor over HTTP. Examples: Laravel Telescope, Sentry's default PHP SDK, Flare's SDK, Inspector.dev's Laravel package.

Pros: easy install (composer require + done), no extra process to supervise, works on any host.

Cons: overhead hits every request and grows with what's captured, HTTP shipping can block on vendor outages if not queued, and state can build up on persistent workers like Octane unless the SDK resets it.

2. Out-of-process (daemon)

A separate long-running process (usually a ReactPHP daemon or system service) that buffers telemetry from your Laravel app and ships it to the dashboard asynchronously. Examples: NightOwl's agent, Laravel Nightwatch package's agent, Datadog's Lambda Extension.

Pros: little work on the request path, crash isolation (agent crash doesn't take down your app), graceful handling of vendor outages (buffers telemetry locally).

Cons: need to supervise the extra process (Supervisor, systemd, Forge daemons), slightly more setup, doesn't fit serverless like Lambda without a Lambda Extension variant.

3. System extension (PHP extension)

A compiled PHP extension that hooks into the runtime at a low level. Can capture data userland PHP can't see: opcache stats, runtime-internal timings, low-overhead stack sampling. Examples: New Relic PHP agent, Tideways PHP extension.

Pros: maximum data richness, often lowest per-request overhead, captures things composer packages can't.

Cons: requires root access to install, has to be built for your exact PHP version (a PHP upgrade waits on a compatible release), ties you to the vendor.

How NightOwl's agent works

Laravel request flow
├── Request arrives at PHP-FPM / Octane worker
├── Nightwatch package observes events (queries, jobs, exceptions, etc.)
├── Worker returns response to user  ← latency budget ends here
├── Nightwatch sends the payload to a local TCP socket (port 2407)
│
└── NightOwl agent (separate ReactPHP process)
    ├── Receives payloads asynchronously from all app workers
    ├── Buffers them in a local SQLite file (WAL mode)
    ├── Batch-writes to your PostgreSQL via COPY protocol
    └── Retries on transient failures

The app worker only serializes the payload and writes it to the socket, after the response has gone out. All heavy lifting (validation, batching, PostgreSQL COPY) happens in the separate agent process. A single agent instance has been benchmarked at 13,400 payloads/s of ingest; writing to PostgreSQL is a separate stage and runs slower.

Why architecture matters for Octane

In Octane, a worker stays alive across many requests (500 by default before Octane recycles it). An in-process agent that doesn't reset its state (event buffers, retry queues, observer registrations) between requests carries it across every request the worker handles, and memory grows until the worker is recycled or runs out.

Out-of-process agents sidestep this: the agent's state is in its own process. Nightwatch opens a connection to the agent for each payload, so the Laravel worker holds no telemetry between requests. This is why NightOwl's architecture is Octane-native and why some SDK-based APMs require extra work to be Octane-safe.

Run the NightOwl agent next to your app

The agent is one Composer package that brings laravel/nightwatch with it and writes to your own PostgreSQL from a separate process. The dashboard shows each agent's ingest rate and buffer depth, so you can see it keeping up.

No credit card needed.

Frequently asked questions

Anything else, write to support@usenightowl.com

What is an APM agent?

An APM agent is the code or process that collects telemetry from your application and ships it to a dashboard. It can be a library loaded into your app (in-process agent), a sidecar process running alongside (out-of-process agent), or a system-level extension (PHP extension, Lambda Layer). The agent's architecture meaningfully affects performance, reliability, and deployment complexity.

What's the difference between an in-process and out-of-process agent?

In-process agents run inside your application's runtime: same PHP process, same memory space. Low deployment complexity, but instrumentation overhead affects every request. Out-of-process agents run as a separate process (ReactPHP daemon, system service, sidecar container). Higher deployment complexity, but less work on the request path because the heavy lifting happens asynchronously.

Which APM agent architecture is best for Laravel?

For production Laravel, out-of-process agents (like NightOwl's ReactPHP-based agent or the Nightwatch package's similar architecture) are the safer default. Nightwatch puts its own overhead at under 3ms per request. In-process agents (Telescope, Sentry's PHP SDK in non-async mode) are simpler to install, and their cost grows with what they capture and where they send it. On Octane, an in-process agent works if it resets its state between requests; one that doesn't will carry memory from request to request.

Do I need to install a system extension for APM?

Usually not for Laravel. Some vendors ship PHP extensions (New Relic, Tideways) that hook into the PHP runtime at a low level. That gives maximum data richness, but requires server root access and extension compatibility per PHP version. Most modern Laravel APMs (NightOwl, Nightwatch, Sentry, Inspector) use pure-PHP agents that install via composer.

How does the APM agent avoid slowing down my Laravel requests?

Three techniques, usually combined. Sampling: record only a percentage of traces. Buffering: collect telemetry and flush it in batches. Out-of-process shipping: hand telemetry to a separate process via a socket or queue once the response is on its way. With NightOwl, the Nightwatch package in your app handles sampling (set by rate in its config, 100% by default) and sends each payload to the local agent after the response; the NightOwl agent buffers to a local SQLite file and writes to PostgreSQL in batches.

What does the APM agent actually collect?

Depends on the product. The Nightwatch package, which NightOwl uses, records HTTP requests (route, duration, status), exceptions (class, stack, context), DB queries (SQL and duration, without bindings), queue jobs (class, duration, status), scheduled tasks, artisan commands, cache operations, outgoing HTTP calls, mail, notifications, and log records. You can switch off queries, cache events, mail, notifications and outgoing requests individually, and sample requests, commands, exceptions and scheduled tasks by rate.

Can I run multiple APM agents?

Yes, they don't conflict. Common pattern: Sentry for errors, NightOwl for performance and Laravel-specific watchers, Datadog for infrastructure. Each agent registers its own handlers. Overhead compounds, though: three agents each adding 2ms means 6ms per request. Prefer one agent that covers what you need.

Keep reading

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