Storing logs in an external service like Datadog is extremely helpful for searching and alerting, but also expensive.

I recently setup a few of our Elixir services to send json-formatted logging to Datadog. The problem is the logs get a lot of noise (and extra cost) from the uptime pings we make to the services. Those are required for other alerting to coordination in the system, but they offer little value in Datadog.

So, how do you skip logging for one particular route? It turns out one great way is through Plug. Alex Koutmos created a Hex package that makes it even easier called Unplug.

For the most part, it just requires making a change to the endpoint.ex file where Plug.Telemetry is added:

  plug Unplug,
    if: {Unplug.Predicates.RequestPathNotIn, ["/healthz"]},
    do: {Plug.Telemetry, event_prefix: [:phoenix, :endpoint]}

That simple logic will exclude the /healthz route. Unplug offers other predicates to follow other logic.