Code Monkey home page Code Monkey logo

plug_telemetry_server_timing's Introduction

Plug.Telemetry.ServerTiming

This library provides support for Server-Timing header in Plug applications by exposing Telemetry events as metrics in HTTP headers. This allows developers to use their's browser DevTools to display server metrics in readable way.

Installation

The package can be installed by adding plug_server_timing to your list of dependencies in mix.exs:

def deps do
  [
    {:plug_telemetry_server_timing, "~> 0.3.0"}
  ]
end

Then add Plug.ServerTiming to your pipeline BEFORE any Plug.Telemetry definitions:

plug Plug.Telemetry.ServerTiming
plug Plug.Telemetry, event_prefix: [:my, :plug]

And then you need to install/1 metrics you will want to see in the DevTools:

Plug.Telemetry.ServerTiming.install([
  {[:my, :plug, :stop], :duration}
])

Now when you will open given page in browsers with support for Server-Timing you will be able to see the data in DevTools, example in Google Chrome:

Google Chrome DevTools image example

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.

License

MIT License

plug_telemetry_server_timing's People

Contributors

hauleth avatar legoscia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

plug_telemetry_server_timing's Issues

Allow for specific ordering of events

So here's my output:

Screen Shot 2020-11-04 at 3 06 47 PM

While you can't tell, its:

  • query decode time
  • query idle time
  • query query time
  • query queue time
  • query total time
  • endpoint stop duration

However my install code looks like this:

    Plug.Telemetry.ServerTiming.install([
      {[:phoenix, :endpoint, :stop], :duration},
      {[:database, :repository, :query], :total_time},
      {[:database, :repository, :query], :decode_time},
      {[:database, :repository, :query], :query_time},
      {[:database, :repository, :query], :queue_time},
      {[:database, :repository, :query], :idle_time}
    ])

How are these orders so different?

Strange output

I'm seeing multiple entries and also the description is cut off after the first space.

Here's my setup:

    Plug.Telemetry.ServerTiming.install([
      {[:phoenix, :endpoint, :stop], :duration, description: "Endpoint Duration"},
      {[:phoenix, :router_dispatch, :stop], :duration, description: "Router Duration"},
      {[:phoenix, :live_view, :mount, :stop], :duration, description: "LiveView Mount Duration"},
      {[:core, :repo, :query], :total_time, description: "Ecto Query Total Time"},
      {[:core, :repo, :query], :decode_time, description: "Ecto Query Decode Time"},
      {[:core, :repo, :query], :query_time, description: "Ecto Query Query Time"},
      {[:core, :repo, :query], :queue_time, description: "Ecto Query Queue Time"},
      {[:core, :repo, :query], :idle_time, description: "Ecto Query Idle Time"}
    ])

Screen Shot 2022-03-21 at 9 46 44 AM

Issue booting with plug

Unchecked dependencies for environment dev:
* plug_telemetry_server_timing (Hex package)
  the dependency does not match the requirement "~> 0.2.0", got "0.0.0-dev"
** (Mix) Can't continue due to errors on dependencies

I don't really understand what's going on here?

Way to rename events?

Hi, I found my event names are way too long:

Screen Shot 2020-11-04 at 3 06 47 PM

Can we create an API for injecting an alias?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.