Our service built with Phoenix framework logged the following message:
The source that recorded this error was the
early_error. Logs are integrated with Datadog, otherwise, we would not have a clue what was the source of this error.
plug_cowboy is Elixir interface to cowboy HTTP server written in Erlang. It helps you to configure Cowboy using Elixir syntax.
Versions, I see versions everywhere!
plug_cowboy evolves in order to provide better interfacing service, and because cowboy itself changes with the same reason. The Source of logged error was how
plug_cowboy handled the logging of broken HTTP requests, it was prior to version 2.4. Version 2.4,
plug_cowboy offers event Instrumentation:
PlugCowboy uses the
:telemetry library for instrumentation. The following span events are published during each request.
That means system observability, a new hipe word discovered by my fellow software testers around a year ago.
Log The Broken HTTP Request Using Plug Cowboy Telemetry
The idea is very simple, when Cowboy encounters a broken HTTP request, Plug Cowboy magically emits the following event:
A single event is published when the request ends with an early error: [:cowboy, :request, :early_error] - dispatched for requests terminated early by Cowboy
You first need to
attach your Elixir application with this event, in
application.ex file, before
start_link function call:
Nothing fancy here, you put the event name, the event that you are interested in (from Plug Cowboy documentation), your module function that will handle the event (arity of a function is always four).
You are most interested in the third parameter that contains the actual HTTP request that caused the error. Here is example for HTTP 431: