All Projects â†’ scoutapp â†’ elixir_plug_server_timing

scoutapp / elixir_plug_server_timing

Licence: MIT license
Bring Elixir/Phoenix server-side performance metrics 📈 to Chrome's Developer Tools via the Server Timing API. Production Safe™.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to elixir plug server timing

Multiverse
Elixir package that allows to add compatibility layers via API gateways.
Stars: ✭ 87 (+77.55%)
Mutual labels:  plug
Absinthe plug
Plug support for Absinthe, the GraphQL toolkit for Elixir
Stars: ✭ 209 (+326.53%)
Mutual labels:  plug
kamon-http4s
Kamon Integration for http4s
Stars: ✭ 47 (-4.08%)
Mutual labels:  tracing
Ewebmachine
The HTTP decision tree as a plug (full elixir rewriting of basho/webmachine with improvements)
Stars: ✭ 95 (+93.88%)
Mutual labels:  plug
Logster
Easily parsable single line, plain text and JSON logger for Plug and Phoenix applications
Stars: ✭ 171 (+248.98%)
Mutual labels:  plug
batiscaph
Currently inactive. Erlang trace visualizer.
Stars: ✭ 37 (-24.49%)
Mutual labels:  tracing
Authex
Authex is an opinionated JWT authentication and authorization library for Elixir.
Stars: ✭ 73 (+48.98%)
Mutual labels:  plug
mongoproxy
Lightweight proxy to collect MongoDb client metrics
Stars: ✭ 26 (-46.94%)
Mutual labels:  tracing
Appsignal Elixir
🟪 AppSignal for Elixir package
Stars: ✭ 176 (+259.18%)
Mutual labels:  plug
iopipe-js
Build and run serverless apps with confidence on AWS Lambda with Tracing, Profiling, Metrics, Monitoring, and more.
Stars: ✭ 33 (-32.65%)
Mutual labels:  tracing
Reverse proxy plug
🔛 an Elixir reverse proxy Plug with HTTP/2, chunked transfer and path proxying support
Stars: ✭ 112 (+128.57%)
Mutual labels:  plug
Plexy
A toolkit for building excellent APIs with Elixir
Stars: ✭ 152 (+210.2%)
Mutual labels:  plug
java-concurrent
OpenTracing-aware helpers related to java.util.concurrent
Stars: ✭ 36 (-26.53%)
Mutual labels:  tracing
Flutter weather bg
A rich and cool weather dynamic background plug-in
Stars: ✭ 89 (+81.63%)
Mutual labels:  plug
plug
A collection of pluggable traits for Eloquent (Laravel) models
Stars: ✭ 13 (-73.47%)
Mutual labels:  plug
Plugapi
A generic API for creating plug.dj bots
Stars: ✭ 83 (+69.39%)
Mutual labels:  plug
iopipe-python
Python agent for AWS Lambda metrics, tracing, profiling & analytics
Stars: ✭ 77 (+57.14%)
Mutual labels:  tracing
mltrace
Coarse-grained lineage and tracing for machine learning pipelines.
Stars: ✭ 449 (+816.33%)
Mutual labels:  tracing
messier
Messier is an app for tracing objective-c methods in an iOS app.
Stars: ✭ 72 (+46.94%)
Mutual labels:  tracing
rbbcc
BCC port for MRI - this is unofficial bonsai project.
Stars: ✭ 45 (-8.16%)
Mutual labels:  tracing

Server Timing Response Headers for Elixir / Phoenix

Bring Phoenix server-side performance metrics 📈 to Chrome's Developer Tools (and other browsers that support the Server Timing API) via the plug_server_timing package. Production Safe™.

Metrics are collected from the scout_apm package. A Scout account is not required.

image

Browser Support

  • Chrome 65+ (Chrome 64 uses an old format of the server timing headers. This isn't supported by the gem).
  • Firefox 59+
  • Opera 52+

Installation

To install and use PlugServerTiming, add it as a dependency in your Mixfile:

# mix.exs
  def deps do
    [
      # ...
+     {:plug_server_timing, "~> 0.0.2"}
    ]
  end

Add PlugServerTiming.Plug to your Plug pipeline:

# lib/my_app_web/router.ex
defmodule MyAppWeb.Router do
  pipeline :browser do
    # ...
+   plug PlugServerTiming.Plug
  end
end

✋Whoa! We're not done yet ... we need to instrument our app's function calls.

Instrumentation

Performance metrics are collected via the scout_apm gem. There's just a couple of steps to instrument your app.

Instrument controllers:

# lib/my_app_web.ex
defmodule MyAppWeb do
  # ...
  def controller do
    quote do
      use Phoenix.Controller, namespace: MyAppWeb
+     use ScoutApm.Instrumentation
      # ...
    end
  end
end

Instrument Ecto queries:

# config/dev.exs
+config :my_app, MyApp.Repo,
+ loggers: [{Ecto.LogEntry, :log, []}, {ScoutApm.Instruments.EctoLogger, :log, []}]

Instrument templates:

# config/dev.exs
+config :phoenix, :template_engines,
+ eex: ScoutApm.Instruments.EExEngine,
+ exs: ScoutApm.Instruments.ExsEngine

Additional instrumentation

To instrument HTTPoison, MongoDB Ecto, and more see the Scout docs.

Custom instrumentation

Collect performance data on additional function calls by adding custom instrumentation via scout_apm. See the docs for instructions.

Security

If you'd like to conditionally include Server-Timing headers depending on authorization, the Plug can be included in a Plug.Builder pipeline or you can directly use PlugServerTiming.Plug.register_before_send_headers/1 in an existing Plug.

defmodule MyExistingAuthPlug do
  @behaviour Plug
  import Plug.Conn

  def init(opts), do: opts

  def call(conn, _opts) do
    case AuthModule.verify_auth(conn) do
      {:ok, :admin} ->
        PlugServerTiming.Plug.register_before_send_headers(conn)
      {:ok, :user} ->
        conn
      {:error, _} ->
        conn
        |> put_status(:unauthorized)
        |> halt()
    end
  end
end

Overhead

The scout_apm package, a dependency of plug_server_timing, applies low overhead instrumentation designed for production use.

Thanks!

Special thank you goes to @OleMchls for writing up https://blog.dnsimple.com/2018/02/server-timing-with-phoenix/ and inspiring this package 💖

Documentation on HexDocs.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].