hauleth

hauleth

Server-Timing header in Phoenix/Plug development

Today I have found about Server-Timing header support in browsers. Its purpose is to allow browser developer tools to display some server metrics next to network durations, example:

(Screenshot from Safari, the long blue bar at the bottom)

(Screenshot from Chrome, again, the long blue bar at the bottom)

For now I have created simple plug that exports them:

defmodule Plugs.ServerTimings do
  @behaviour Plug

  import Plug.Conn

  @impl true
  def init(opts) do
    opts
  end

  @impl true
  def call(conn, _) do
    start_time = System.monotonic_time()
    millis = System.convert_time_unit(1, :millisecond, :native)

    register_before_send(conn, fn conn ->
      mono_duration = IO.inspect(System.monotonic_time() - start_time)
      duration = mono_duration / millis

      conn
      |> put_resp_header("server-timing", "plug;dur=#{duration}")
    end)
  end
end

But this is very simple and basic. I tried to use Telemetry together with this, but it worked out rather poorly. Having Telemetry with such would be pretty useful, as it would allow to display other metrics in one timeline:

  • Template rendering time
  • DB queries
  • External services requests
  • Etc.

(Right now the feature set in Server-Timing is rather sparse, as it do not allow for example to state “start” time, which would allow more detailed, tracing-like, information within such view)

What do you think, and what are the possibilities for rendering such informations or even to integrate it into Phoenix/Plug itself.

Most Liked

hauleth

hauleth

I have just published library that provides above plug as a independent library

https://github.com/hauleth/plug_telemetry_server_timing

Where Next?

Popular in Discussions Top

AstonJ
Are there any Elixir or Erlang libraries that help with this? I’ve been thinking how streaming services like twitch have exploded recentl...
New
lorenzo
Hey everone! I created a prototype for my app using Nodejs for the api. But the framework I chose wasnt great (in general theresnt any g...
New
lucaong
Hello Elixir and Nerves community, I have been working for a while on an open-source embedded key-value database for Elixir, that I call...
230 14403 124
New
owaisqayum
I have a sample string sentence = "Hello, world ... 123 *** ^%&*())^% %%:>" From this string, I want to only keep the integers, ...
New
pillaiindu
I want to convert a Phoenix LiveView CRUD website to a CRUD mobile app. What do you think is the easiest way to do so?
New
Rustixir
Hi everyone, im working on find best language/framework/system for high concurrency, high performance and stable performance after wor...
New
matthias_toepp
I’d love to hear what people think about Wisp, the new Gleam web framework started by Gleam’s primary creator Louis Pilfold. Gleam, alon...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

We're in Beta

About us Mission Statement