Plug.Telemetry.ServerTiming (plug_telemetry_server_timing v0.2.0) View Source
This plug provide support for Server-Timing header that allows to
display server-side measurements in browser developer tools and access it
programatically via Performance API in JavaScript.
Usage
Just add it as a plug into your pipeline:
plug Plug.Telemetry.ServerTimingAnd call install/1 with list of {event_name, measurement} in your
application startup, for example for Phoenix and Ecto application:
Plug.Telemetry.ServerTiming.install([
{[:phoenix, :endpoint, :stop], :duration},
{[:my_app, :repo, :query], :queue_time},
{[:my_app, :repo, :query], :query_time},
{[:my_app, :repo, :query], :decode_time}
])Important
You need to place this plug BEFORE Plug.Telemetry call as otherwise it
will not see it's events (before_send callbacks are called in reverse order
of declaration, so this one need to be added before Plug.Telemetry one.
Caveats
This will not respond with events that happened in separate processes, only events that happened in the Plug process will be recorded.
WARNING
Current specification of Server-Timing do not provide a way to specify event
start time, which mean, that the data displayed in the DevTools isn't trace
report (like the content of the "regular" HTTP timings) but raw dump of the data
displayed as a bars. This can be a little bit confusing, but right now there is
nothing I can do about it.
Link to this section Summary
Functions
Define which events should be available within response headers.
Link to this section Types
Specs
event() ::
{:telemetry.event_name(), atom()}
| {:telemetry.event_name(), atom(), keyword() | map()}
Specs
events() :: [event()]
Link to this section Functions
Specs
install(events) :: :ok when events: map() | [{:telemetry.event_name(), atom()}]
Define which events should be available within response headers.