You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once that entry has been added to you endpoint.ex file, you can simple call ServerTimingPlug.capture_timing/3 and
ServerTimingPlug.capture_timing/3 throughout your code in order to capture timings. The captured timings will
be flushed when the response goes out. It is important to note that timings will only be available if the call to
ServerTimingPlug.capture_timing is made in the same process as the process that is handling the request. A sample
timing capture could look something like this:
defindex(conn,params)dostart_time=System.monotonic_time()## Something expensive is done here#duration=System.monotonic_time()-start_timeServerTimingPlug.capture_timing("expensive-thing",duration,"This timing captures the expensive operation")json(conn,%{message: "All is well!"})end
Additional Thoughts
The design of this lib draws inspiration from https://github.com/hauleth/plug_telemetry_server_timing, but makes
some slightly different design decisions. Whereas plug_telemetry_server_timing attaches :telemetry handlers to
events and automatically aggregates the results of timings, this library allows you to time arbitrary events and
does not infer timing label names based on telemetry events. There are other Server-Timing libraries on hex as well;
Which one you choose depends on your specific needs :).
About
A plug that will generate serving timing headers for Plug based applications