Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Telemetry

 Telemetry

In this talk, we'll look at Telemetry, a new project for metrics and monitoring in the Elixir ecosystem. Telemetry provides libraries for gathering monitoring data from libraries and applications. It's already integrated with Ecto and is coming soon to Phoenix. We'll go through the design and thought process behind it, discuss the rationale for the not-so-obvious decisions, and most importantly, see the bright future of using a unified monitoring solution throughout the community.

Arkadiusz Gil

April 09, 2019
Tweet

More Decks by Arkadiusz Gil

Other Decks in Technology

Transcript

  1. @arkgil @_arkgil def handle_request(host, path, method, headers, body) do params

    = decode(body) case MyApp.business_logic(params) do {:ok, data} -> body = encode(data) send_resp(200, body) :error -> body = %{error: "Oops"} send_resp(400, body) end end
  2. @arkgil @_arkgil def business_logic(params) do update_counter(“my_app.business_logic”, ...) with :ok <-

    authorize(params), {:ok, data} <- query_database(params), :ok <- push_event(data) do {:ok, data} end end
  3. @arkgil @_arkgil def authorize(params) do update_counter("my_app.auth.requests", ...) ... end def

    query_database(params) do update_counter("my_app.db.queries", ...) ... end def push_event(params) do update_counter("my_app.broker.events_pushed", ...) ... end
  4. @arkgil @_arkgil def handle_request(host, method, body) do params = decode(body)

    update_counter(“my_app.http.requests”, ...) update_sum(“my_app.http.payload_size", ...) case MyApp.business_logic(params) do {:ok, data} -> update_counter(“my_app.http.responses”, ...) 
 update_statistics(“my_app.http.response_time”, ...) body = encode(data) send_resp(200, body) :error -> update_counter(“my_app.http.responses", ...) 
 update_statistics(“my_app.http.response_time”, ...) body = %{error: "Oops"} send_resp(400, body) end end
  5. @arkgil @_arkgil The monitoring and reporting systems should be like

    an exoskeleton built around your system, not woven into it. - Michael Nygard, Release It!, 2nd ed.
  6. @arkgil @_arkgil def handle_http_start( event, measurements, metadata, config ) do

    update_counter("my_app.http.requests", ...) update_sum( "my_app.http.payload_size", 
 measurements.payload_size, … ) end
  7. @arkgil @_arkgil def handle_request(host, method, body) do params = decode(body)

    :telemetry.execute([:my_app, :http, :request, :start], ...) case MyApp.business_logic(params) do {:ok, data} -> body = encode(data) :telemetry.execute([:my_app, :http, :request, :stop], ...) send_resp(200, body) :error -> :telemetry.execute([:my_app, :http, :request, :stop], ...) body = %{error: "Oops"} send_resp(400, body) end end