diff --git a/config/config.exs b/config/config.exs index 1dc4b7d27..f5e86c4d7 100644 --- a/config/config.exs +++ b/config/config.exs @@ -41,9 +41,6 @@ config :ex_aws, :hackney_opts, config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase -config :hackney, mod_metrics: :hackney_telemetry -config :hackney_telemetry, report_interval: 5_000 - config :screens, redirect_http?: true, keycloak_role: "screens-admin" diff --git a/lib/screens/telemetry.ex b/lib/screens/telemetry.ex index e4760004d..95a470eb1 100644 --- a/lib/screens/telemetry.ex +++ b/lib/screens/telemetry.ex @@ -13,33 +13,26 @@ defmodule Screens.Telemetry do def init(_) do handlers = [ # V3 API - log_span(~w[screens v3_api get_json]a, metadata: ~w[url cached]a), + handle_span(~w[screens v3_api get_json]a, metadata: ~w[url cached]a), # Stops - log_span(~w[screens stops stop fetch_stop_name]a, metadata: ~w[stop_id]), - log_span(~w[screens stops stop fetch_location_context]a, metadata: ~w[app stop_id]), + handle_span(~w[screens stops stop fetch_stop_name]a, metadata: ~w[stop_id]), + handle_span(~w[screens stops stop fetch_location_context]a, metadata: ~w[app stop_id]), # Alerts - log_span(~w[screens alerts alert fetch]a), + handle_span(~w[screens alerts alert fetch]a), # Routes - log_span(~w[screens routes route fetch_routes_by_stop]a, + handle_span(~w[screens routes route fetch_routes_by_stop]a, metadata: ~w[stop_id type_filters]a ), # DUP Candidate Generator - log_span(~w[screens v2 candidate_generator dup departures_instances]a), - log_span(~w[screens v2 candidate_generator dup departures get_section_data]a), - log_span(~w[screens v2 candidate_generator dup departures get_sections_data]a), - log_span(~w[screens v2 candidate_generator dup header_instances]a), - log_span(~w[screens v2 candidate_generator dup alerts_instances]a), - log_span(~w[screens v2 candidate_generator dup evergreen_content_instances]a), - - # events - log_event(~w[hackney_pool]a, - metadata: ~w[pool]a, - measurements: ~w[free_count in_use_count no_socket queue_count take_rate]a - ) + handle_span(~w[screens v2 candidate_generator dup departures_instances]a), + handle_span(~w[screens v2 candidate_generator dup departures get_section_data]a), + handle_span(~w[screens v2 candidate_generator dup departures get_sections_data]a), + handle_span(~w[screens v2 candidate_generator dup header_instances]a), + handle_span(~w[screens v2 candidate_generator dup alerts_instances]a), + handle_span(~w[screens v2 candidate_generator dup evergreen_content_instances]a) ] for {name, event_names, config} <- handlers do - event_names = wrap_event_names(event_names) :ok = :telemetry.attach_many(name, event_names, &Screens.Telemetry.handle_event/4, config) end @@ -126,25 +119,7 @@ defmodule Screens.Telemetry do @default_metadata ~w[span_id parent_id correlation_id request_id]a @default_measurements ~w[duration]a - defp log_span(name, config \\ []) when is_list(name) do - config = build_config(config) - - events = [ - name ++ [:start], - name ++ [:stop], - name ++ [:exception] - ] - - {Enum.join(name, "."), events, config} - end - - defp log_event(name, config) when is_list(name) do - config = build_config(config) - - {Enum.join(name, "."), name, config} - end - - defp build_config(config) do + defp handle_span(name, config \\ []) when is_list(name) do metadata = config |> Keyword.get(:metadata, []) @@ -157,10 +132,18 @@ defmodule Screens.Telemetry do |> Enum.concat(@default_measurements) |> Enum.uniq() - %{ + config = %{ metadata: metadata, measurements: measurements } + + events = [ + name ++ [:start], + name ++ [:stop], + name ++ [:exception] + ] + + {Enum.join(name, "."), events, config} end defp to_log(enum) do @@ -169,7 +152,4 @@ defmodule Screens.Telemetry do end |> Enum.intersperse(" ") end - - defp wrap_event_names([[_ | _] | _] = event_names), do: event_names - defp wrap_event_names(event_names), do: [event_names] end diff --git a/mix.exs b/mix.exs index dbabb1dbe..d3335169f 100644 --- a/mix.exs +++ b/mix.exs @@ -23,7 +23,7 @@ defmodule Screens.MixProject do # # Type `mix help compile.app` for more information. def application do - apps = [:logger, :runtime_tools, :hackney_telemetry] + apps = [:logger, :runtime_tools] apps = case Mix.env() do @@ -81,15 +81,14 @@ defmodule Screens.MixProject do {:stream_data, "~> 1.1", only: :test}, {:memcachex, "~> 0.5.5"}, {:aja, "~> 0.6.2"}, - {:telemetry, "~> 1.2", override: true}, + {:telemetry, "~> 1.2"}, {:telemetry_poller, "~> 0.4"}, {:telemetry_metrics, "~> 0.4"}, {:screens_config, git: "https://github.com/mbta/screens-config-lib.git", ref: "25fb47c58fc0b485c8c6df78fe94914292856903"}, {:nebulex, "~> 2.6"}, - {:remote_ip, "~> 1.2"}, - {:hackney_telemetry, "~> 0.1.1"} + {:remote_ip, "~> 1.2"} ] end end diff --git a/mix.lock b/mix.lock index fb6be812e..3af828f07 100644 --- a/mix.lock +++ b/mix.lock @@ -22,7 +22,6 @@ "gettext": {:hex, :gettext, "0.22.3", "c8273e78db4a0bb6fba7e9f0fd881112f349a3117f7f7c598fa18c66c888e524", [:mix], [{:expo, "~> 0.4.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "935f23447713954a6866f1bb28c3a878c4c011e802bcd68a726f5e558e4b64bd"}, "guardian": {:hex, :guardian, "2.3.2", "78003504b987f2b189d76ccf9496ceaa6a454bb2763627702233f31eb7212881", [:mix], [{:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "b189ff38cd46a22a8a824866a6867ca8722942347f13c33f7d23126af8821b52"}, "hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"}, - "hackney_telemetry": {:hex, :hackney_telemetry, "0.1.1", "eccc245099ca244fa66093474297f6c5cd25780fb4cecb933c59ad63ca7255c9", [:rebar3], [{:telemetry, "1.0.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "547093c1da833e7fe625c2bf99fdc83e1b8eb4dd7d53e276c7ea20173628348e"}, "httpoison": {:hex, :httpoison, "2.2.1", "87b7ed6d95db0389f7df02779644171d7319d319178f6680438167d7b69b1f3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "51364e6d2f429d80e14fe4b5f8e39719cacd03eb3f9a9286e61e216feac2d2df"}, "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},