Monitoring our own Control4 driver with Anvil
The Anvil Agent is a Control4 driver too, running on controllers we don't own. Here's why a general-purpose error tracker like Sentry struggles with a Lua driver, and how the agent reports its own errors and logs through Anvil instead.
Control4 drivers are Lua programs that run inside Director on a Control4 controller. Anvil captures their errors, logs and events: the Driverforge SDK runs inside each instrumented driver, and the Anvil Agent, installed on the same controller, sends what it collects to Anvil.
The Anvil Agent is itself a Control4 driver, running on developers' controllers that we don't own and can't log in to. When it fails, we need to know as much as any driver developer would. So it reports its own errors and logs through Anvil, the same way your driver does.
Why Sentry is a poor fit for a Control4 driver
If you've used Sentry or Bugsnag on a web or mobile app, they're the obvious first reach for a driver too, and we started there. A Control4 driver makes it hard work.
No SDK. A driver's Lua sandbox can't load a vendor SDK, so you end up writing your own client against the tracker's HTTP API, using the platform's network calls. Everything an SDK normally handles becomes yours: wrapping entry points so unhandled errors are caught, attaching context, and limiting how much one failing controller can send.
Details an SDK would get right. Timestamps are a good example. A formatted date string without a timezone can be read as local time, and whole-second precision loses the order of errors raised in the same second. Send a numeric Unix timestamp with fractional milliseconds instead; it's unambiguous and keeps that order.
No Lua. Sentry has no Lua platform, so a driver's project has to borrow another platform's identity. Events arrive, but the stack traces don't fit what the interface expects, and the frames show up as an awkwardly formatted attachment rather than a trace you can read.
No idea what a driver is. A general-purpose tracker doesn't know which handler was running, what Director passed it, which controller it was on or which version of the driver was installed. For a driver, that's most of what you need to know.
Sentry is excellent at what it's built for, and our cloud services still use it. A Control4 driver just isn't what it's built for.
Anvil on Anvil
The agent's errors now arrive in Anvil exactly like any instrumented driver's: grouped into issues, with the stack, the values in play and the controller and version they came from. We read them in the same screens our customers use, which means we use those screens every day. Much of the error tracking Anvil does today came from fixing what got in our way while doing that.
A driver can't always reach the internet, and an error report lost to a dropped connection is exactly the one you'd want. The agent keeps reports it couldn't send in a queue in the controller's key-value store, so they survive a restart. The queue holds up to 100 reports, drops the oldest when it's full, and sends the backlog after the next successful report. It's a pattern worth copying in any driver that reports somewhere over the network.
Forwarding logs without a feedback loop
The agent's logs go to Anvil too, so nobody has to read them in Composer's Lua output window on a controller they can get to. Shipping them has a catch that any driver forwarding its own logs will hit.
Sending a log line over the network makes the network code log something, and forwarding that log line makes the network code log something else, and so on, until the driver is doing nothing but logging about logging. The agent breaks the loop in two places. Capturing a log line is just an insert into a buffer, with no logging or sending of its own. A timer flushes that buffer, and while the flush runs, a guard keeps any log lines produced by the sending code on the controller instead of feeding them back into the buffer.
Two tools, each where it fits
Our cloud services report to Sentry, which handles them well. The Anvil Agent, the one piece of our stack that runs on a Control4 controller, reports to Anvil, because Anvil is built for Control4 drivers. That's the same choice we'd suggest to any driver developer: keep the tools you already use for your web and cloud code, and use Anvil for the driver.