{"id":23330372,"url":"https://github.com/scoutapp/elixir_plug_server_timing","last_synced_at":"2025-08-23T00:31:03.017Z","repository":{"id":57535162,"uuid":"123950412","full_name":"scoutapp/elixir_plug_server_timing","owner":"scoutapp","description":"Bring Elixir/Phoenix server-side performance metrics 📈 to Chrome's Developer Tools via the Server Timing API. Production Safe™.","archived":false,"fork":false,"pushed_at":"2018-12-15T21:16:53.000Z","size":40,"stargazers_count":47,"open_issues_count":1,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-05-16T17:03:16.294Z","etag":null,"topics":["elixir","monitoring","performance","plug","tracing"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scoutapp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-05T16:55:57.000Z","updated_at":"2024-04-07T08:42:42.000Z","dependencies_parsed_at":"2022-09-26T18:21:51.524Z","dependency_job_id":null,"html_url":"https://github.com/scoutapp/elixir_plug_server_timing","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scoutapp%2Felixir_plug_server_timing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scoutapp%2Felixir_plug_server_timing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scoutapp%2Felixir_plug_server_timing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scoutapp%2Felixir_plug_server_timing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scoutapp","download_url":"https://codeload.github.com/scoutapp/elixir_plug_server_timing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230650636,"owners_count":18259293,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","monitoring","performance","plug","tracing"],"created_at":"2024-12-20T22:16:43.438Z","updated_at":"2024-12-20T22:16:44.174Z","avatar_url":"https://github.com/scoutapp.png","language":"Elixir","readme":"# Server Timing Response Headers for Elixir / Phoenix\n\nBring Phoenix server-side performance metrics 📈 to Chrome's Developer Tools (and other browsers that support the [Server Timing API](https://w3c.github.io/server-timing/)) via the `plug_server_timing` package. Production Safe™.\n\nMetrics are collected from the [scout_apm](https://github.com/scoutapp/scout_apm_elixir) package. A [Scout](https://scoutapp.com) account is not required.\n\n![image](https://s3-us-west-1.amazonaws.com/scout-blog/elixir_server_timing.png)\n\n## Browser Support\n\n- Chrome 65+ (Chrome 64 uses an [old format](https://github.com/scoutapp/ruby_server_timing/issues/5#issuecomment-370504687) of the server timing headers. This isn't supported by the gem).\n- Firefox 59+\n- Opera 52+\n\n## Installation\n\nTo install and use `PlugServerTiming`, add it as a dependency in your Mixfile:\n\n```diff\n# mix.exs\n  def deps do\n    [\n      # ...\n+     {:plug_server_timing, \"~\u003e 0.0.2\"}\n    ]\n  end\n```\n\nAdd `PlugServerTiming.Plug` to your Plug pipeline: \n\n```diff\n# lib/my_app_web/router.ex\ndefmodule MyAppWeb.Router do\n  pipeline :browser do\n    # ...\n+   plug PlugServerTiming.Plug\n  end\nend\n```\n\n✋Whoa! __We're not done yet__ ... we need to instrument our app's function calls.\n\n## Instrumentation\n\nPerformance metrics are collected via the `scout_apm` gem. There's just a couple of steps to instrument your app.\n\n__Instrument controllers:__\n\n```diff\n# lib/my_app_web.ex\ndefmodule MyAppWeb do\n  # ...\n  def controller do\n    quote do\n      use Phoenix.Controller, namespace: MyAppWeb\n+     use ScoutApm.Instrumentation\n      # ...\n    end\n  end\nend\n```\n\n__Instrument Ecto queries:__\n\n```diff\n# config/dev.exs\n+config :my_app, MyApp.Repo,\n+ loggers: [{Ecto.LogEntry, :log, []}, {ScoutApm.Instruments.EctoLogger, :log, []}]\n```\n\n__Instrument templates:__\n\n```diff\n# config/dev.exs\n+config :phoenix, :template_engines,\n+ eex: ScoutApm.Instruments.EExEngine,\n+ exs: ScoutApm.Instruments.ExsEngine\n```\n\n### Additional instrumentation\n\nTo instrument HTTPoison, MongoDB Ecto, and more see the [Scout docs](http://help.apm.scoutapp.com/#instrumenting-common-libraries).\n\n### Custom instrumentation\n\nCollect performance data on additional function calls by adding custom instrumentation via `scout_apm`. [See the docs for instructions](http://help.apm.scoutapp.com/#elixir-custom-instrumentation).\n\n## Security\n\nIf 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`.\n\n```elixir\n\ndefmodule MyExistingAuthPlug do\n  @behaviour Plug\n  import Plug.Conn\n\n  def init(opts), do: opts\n\n  def call(conn, _opts) do\n    case AuthModule.verify_auth(conn) do\n      {:ok, :admin} -\u003e\n        PlugServerTiming.Plug.register_before_send_headers(conn)\n      {:ok, :user} -\u003e\n        conn\n      {:error, _} -\u003e\n        conn\n        |\u003e put_status(:unauthorized)\n        |\u003e halt()\n    end\n  end\nend\n```\n\n## Overhead\n\nThe `scout_apm` package, a dependency of `plug_server_timing`, applies low overhead instrumentation designed for production use.\n\n## Thanks!\n\nSpecial thank you goes to [@OleMchls](https://github.com/OleMchls) for writing up https://blog.dnsimple.com/2018/02/server-timing-with-phoenix/ and inspiring this package 💖\n\n[Documentation on HexDocs](https://hexdocs.pm/plug_server_timing).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscoutapp%2Felixir_plug_server_timing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscoutapp%2Felixir_plug_server_timing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscoutapp%2Felixir_plug_server_timing/lists"}