Skip to content

Commit f3d1282

Browse files
committed
chore: disable unneeded telemetry logging
This method of sending telemetry was regularly overloading the Splunk log handler and causing more important logs to be dropped (in particular DeviceMonitor, which we rely on for alerting us to screen outages). We have not actually used these log spans to investigate anything in a long time, so we'll remove them until we may need them again.
1 parent 433c785 commit f3d1282

File tree

8 files changed

+119
-199
lines changed

8 files changed

+119
-199
lines changed

config/config.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ config :ex_aws, json_codec: Jason
3838
config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase
3939

4040
config :hackney, mod_metrics: :hackney_telemetry
41-
config :hackney_telemetry, report_interval: 5_000
41+
config :hackney_telemetry, report_interval: 10_000
4242

4343
config :screens,
4444
redirect_http?: true,

lib/screens/alerts/alert.ex

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -159,29 +159,27 @@ defmodule Screens.Alerts.Alert do
159159

160160
@callback fetch(options()) :: result()
161161
def fetch(opts \\ [], get_json_fn \\ &V3Api.get_json/2) do
162-
Screens.Telemetry.span([:screens, :alerts, :alert, :fetch], fn ->
163-
includes =
164-
if Keyword.get(opts, :include_all?, false),
165-
do: @all_includes,
166-
else: @base_includes
167-
168-
params =
169-
opts
170-
|> Enum.flat_map(&format_query_param/1)
171-
|> Map.new()
172-
|> Map.put("include", Enum.join(includes, ","))
173-
174-
case get_json_fn.("alerts", params) do
175-
{:ok, response} ->
176-
{:ok,
177-
response
178-
|> V3Api.Parser.parse()
179-
|> normalize_informed_entities_for_direction_id()}
180-
181-
_ ->
182-
:error
183-
end
184-
end)
162+
includes =
163+
if Keyword.get(opts, :include_all?, false),
164+
do: @all_includes,
165+
else: @base_includes
166+
167+
params =
168+
opts
169+
|> Enum.flat_map(&format_query_param/1)
170+
|> Map.new()
171+
|> Map.put("include", Enum.join(includes, ","))
172+
173+
case get_json_fn.("alerts", params) do
174+
{:ok, response} ->
175+
{:ok,
176+
response
177+
|> V3Api.Parser.parse()
178+
|> normalize_informed_entities_for_direction_id()}
179+
180+
_ ->
181+
:error
182+
end
185183
end
186184

187185
@doc """

lib/screens/stops/stop.ex

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,10 @@ defmodule Screens.Stops.Stop do
8383

8484
@callback fetch_stop_name(id()) :: String.t() | nil
8585
def fetch_stop_name(stop_id) do
86-
Screens.Telemetry.span(~w[screens stops stop fetch_stop_name]a, %{stop_id: stop_id}, fn ->
87-
case fetch(%{ids: [stop_id]}) do
88-
{:ok, [%__MODULE__{name: name}]} -> name
89-
_ -> nil
90-
end
91-
end)
86+
case fetch(%{ids: [stop_id]}) do
87+
{:ok, [%__MODULE__{name: name}]} -> name
88+
_ -> nil
89+
end
9290
end
9391

9492
@spec fetch_subway_platforms_for_stop(id()) :: [t()]

lib/screens/telemetry.ex

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,11 @@ defmodule Screens.Telemetry do
1111
@impl Supervisor
1212
def init(_) do
1313
handlers = [
14-
# V3 API
15-
log_span(~w[screens v3_api get_json]a, metadata: ~w[path query cache]a),
16-
# Stops
17-
log_span(~w[screens stops stop fetch_stop_name]a, metadata: ~w[stop_id]),
18-
# Location Context
19-
log_span(~w[screens location_context fetch]a, metadata: ~w[app stop_id]),
20-
# Alerts
21-
log_span(~w[screens alerts alert fetch]a),
22-
# Routes
23-
log_span(~w[screens routes route fetch_routes_by_stop]a,
24-
metadata: ~w[stop_id type_filters]a
25-
),
26-
# DUP Candidate Generator
27-
log_span(~w[screens v2 candidate_generator dup]a),
28-
log_span(~w[screens v2 candidate_generator dup departures_instances]a),
29-
log_span(~w[screens v2 candidate_generator dup departures get_section_data]a),
30-
log_span(~w[screens v2 candidate_generator dup departures get_sections_data]a),
31-
log_span(~w[screens v2 candidate_generator dup header_instances]a),
32-
log_span(~w[screens v2 candidate_generator dup alerts_instances]a),
33-
log_span(~w[screens v2 candidate_generator dup evergreen_content_instances]a),
34-
# New DUP Candidate Generator
35-
log_span(~w[screens v2 candidate_generator dup_new]a),
36-
log_span(~w[screens v2 candidate_generator dup_new departures_instances]a),
37-
log_span(~w[screens v2 candidate_generator dup_new evergreen_instances]a),
38-
log_span(~w[screens v2 candidate_generator dup_new header_instances]a),
14+
# example span to avoid unused function warnings; nothing emits this
15+
log_span(~w[screens example_event]a),
16+
17+
# enable V3 API span logging (WARNING: high log volume)
18+
# log_span(~w[screens v3_api get_json]a, metadata: ~w[path query cache]a),
3919

4020
# events
4121
log_event(~w[hackney_pool]a,
@@ -59,7 +39,8 @@ defmodule Screens.Telemetry do
5939
measurements: [
6040
{Screens.V3Api.Cache.Realtime, :dispatch_stats, []},
6141
{Screens.V3Api.Cache.Static, :dispatch_stats, []}
62-
]
42+
],
43+
period: 10_000
6344
}
6445
]
6546

lib/screens/v2/candidate_generator/dup.ex

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,16 @@ defmodule Screens.V2.CandidateGenerator.Dup do
7777
departures_instances_fn \\ &DeparturesInstances.departures_instances/2,
7878
alerts_instances_fn \\ &AlertsInstances.alert_instances/2
7979
) do
80-
Screens.Telemetry.span([:screens, :v2, :candidate_generator, :dup], fn ->
81-
ctx = Screens.Telemetry.context()
82-
83-
[
84-
span_thunk(:header_instances, ctx, fn -> header_instances_fn.(config, now) end),
85-
span_thunk(:alerts_instances, ctx, fn -> alerts_instances_fn.(config, now) end),
86-
span_thunk(:departures_instances, ctx, fn -> departures_instances_fn.(config, now) end),
87-
span_thunk(:evergreen_content_instances, ctx, fn ->
88-
evergreen_content_instances_fn.(config, now)
89-
end)
90-
]
91-
|> Task.async_stream(& &1.(), timeout: 30_000)
92-
|> Enum.flat_map(fn {:ok, instances} -> instances end)
93-
end)
80+
[
81+
fn -> header_instances_fn.(config, now) end,
82+
fn -> alerts_instances_fn.(config, now) end,
83+
fn -> departures_instances_fn.(config, now) end,
84+
fn -> evergreen_content_instances_fn.(config, now) end
85+
]
86+
|> Task.async_stream(& &1.(), timeout: 30_000)
87+
|> Enum.flat_map(fn {:ok, instances} -> instances end)
9488
end
9589

9690
@impl CandidateGenerator
9791
def audio_only_instances(_widgets, _config), do: []
98-
99-
defp span_thunk(name, meta, fun) when is_atom(name) and is_function(fun, 0) do
100-
fn ->
101-
Screens.Telemetry.span([:screens, :v2, :candidate_generator, :dup, name], meta, fun)
102-
end
103-
end
10492
end

lib/screens/v2/candidate_generator/dup/departures.ex

Lines changed: 44 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -294,87 +294,61 @@ defmodule Screens.V2.CandidateGenerator.Dup.Departures do
294294
fetch_routes_fn,
295295
now
296296
) do
297-
Screens.Telemetry.span(
298-
[:screens, :v2, :candidate_generator, :dup, :departures, :get_sections_data],
299-
fn ->
300-
ctx = Screens.Telemetry.context()
301-
302-
sections
303-
|> Task.async_stream(
304-
&get_section_data(
305-
&1,
306-
fetch_departures_fn,
307-
fetch_alerts_fn,
308-
fetch_routes_fn,
309-
now,
310-
ctx
311-
),
312-
on_timeout: :kill_task
313-
)
314-
|> Enum.map(fn
315-
{:ok, data} ->
316-
data
317-
318-
{:exit, reason} ->
319-
ctx =
320-
Screens.Telemetry.context()
321-
|> to_log()
322-
323-
Logger.error(["event=get_section_data.exit reason=#{reason} ", ctx])
324-
raise "Failed to get section data"
325-
end)
326-
end
297+
sections
298+
|> Task.async_stream(
299+
&get_section_data(&1, fetch_departures_fn, fetch_alerts_fn, fetch_routes_fn, now),
300+
on_timeout: :kill_task
327301
)
302+
|> Enum.map(fn
303+
{:ok, data} ->
304+
data
305+
306+
{:exit, reason} ->
307+
Logger.error("get_section_data.exit reason=#{reason}")
308+
raise "Failed to get section data"
309+
end)
328310
end
329311

330312
defp get_section_data(
331313
%Section{query: %Query{params: %Params{stop_ids: stop_ids} = params}} = section,
332314
fetch_departures_fn,
333315
fetch_alerts_fn,
334316
fetch_routes_fn,
335-
now,
336-
ctx
317+
now
337318
) do
338-
Screens.Telemetry.span(
339-
[:screens, :v2, :candidate_generator, :dup, :departures, :get_section_data],
340-
ctx,
341-
fn ->
342-
routes = get_routes_serving_section(params, fetch_routes_fn)
343-
# DUP sections will always show no more than one mode.
344-
# For subway, each route will have its own section.
345-
# If the stop is served by two different subway/light rail routes, route_ids must be populated for each section
346-
# Otherwise, we only need the first route in the list of routes serving the stop.
347-
primary_route_for_section = List.first(routes)
348-
349-
disabled_modes = Screens.Config.Cache.disabled_modes()
350-
351-
# If we know the predictions are unreliable, don't even bother fetching them.
352-
if is_nil(primary_route_for_section) or
353-
primary_route_for_section.type in disabled_modes do
354-
%{type: :no_data_section, route: primary_route_for_section}
355-
else
356-
section_departures =
357-
case Widgets.Departures.fetch_section_departures(
358-
section,
359-
disabled_modes,
360-
fetch_departures_fn
361-
) do
362-
{:ok, departures} -> departures
363-
:error -> []
364-
end
319+
routes = get_routes_serving_section(params, fetch_routes_fn)
320+
# DUP sections will always show no more than one mode.
321+
# For subway, each route will have its own section.
322+
# If the stop is served by two different subway/light rail routes, route_ids must be populated for each section
323+
# Otherwise, we only need the first route in the list of routes serving the stop.
324+
primary_route_for_section = List.first(routes)
325+
326+
disabled_modes = Screens.Config.Cache.disabled_modes()
327+
328+
# If we know the predictions are unreliable, don't even bother fetching them.
329+
if is_nil(primary_route_for_section) or primary_route_for_section.type in disabled_modes do
330+
%{type: :no_data_section, route: primary_route_for_section}
331+
else
332+
section_departures =
333+
case Widgets.Departures.fetch_section_departures(
334+
section,
335+
disabled_modes,
336+
fetch_departures_fn
337+
) do
338+
{:ok, departures} -> departures
339+
:error -> []
340+
end
365341

366-
alert_informed_entities = get_section_entities(params, fetch_alerts_fn, now)
342+
alert_informed_entities = get_section_entities(params, fetch_alerts_fn, now)
367343

368-
%{
369-
departures: section_departures,
370-
alert_informed_entities: alert_informed_entities,
371-
stop_ids: stop_ids,
372-
routes: routes,
373-
params: params
374-
}
375-
end
376-
end
377-
)
344+
%{
345+
departures: section_departures,
346+
alert_informed_entities: alert_informed_entities,
347+
stop_ids: stop_ids,
348+
routes: routes,
349+
params: params
350+
}
351+
end
378352
end
379353

380354
defp get_section_route_from_entities(
@@ -742,10 +716,6 @@ defmodule Screens.V2.CandidateGenerator.Dup.Departures do
742716
|> Enum.uniq()
743717
end
744718

745-
defp to_log(map) do
746-
Enum.map_join(map, " ", fn {k, v} -> "#{k}=#{v}" end)
747-
end
748-
749719
defp headway_time_range(stop_ids, routes, now) do
750720
all_headways =
751721
for stop_id <- stop_ids, %{id: route_id} <- routes do

lib/screens/v2/candidate_generator/dup_new.ex

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
11
defmodule Screens.V2.CandidateGenerator.DupNew do
22
@moduledoc false
33

4-
alias Screens.Telemetry
54
alias Screens.V2.CandidateGenerator
65
alias Screens.V2.CandidateGenerator.Widgets
76

87
alias __MODULE__.Departures
98

109
@behaviour CandidateGenerator
1110

12-
@telemetry_name ~w[screens v2 candidate_generator dup_new]a
1311
@instance_generators [
14-
header_instances: &Widgets.Header.instances/2,
15-
departures_instances: &Departures.instances/2,
16-
evergreen_instances: &Widgets.Evergreen.evergreen_content_instances/2
17-
]
18-
|> Enum.map(fn {name, func} -> {@telemetry_name ++ [name], func} end)
12+
&Widgets.Header.instances/2,
13+
&Departures.instances/2,
14+
&Widgets.Evergreen.evergreen_content_instances/2
15+
]
1916

2017
@impl CandidateGenerator
2118
defdelegate screen_template(screen), to: Screens.V2.CandidateGenerator.Dup
2219

2320
@impl CandidateGenerator
2421
def candidate_instances(config, now \\ DateTime.utc_now()) do
25-
Telemetry.span(@telemetry_name, fn ->
26-
context = Telemetry.context()
27-
28-
@instance_generators
29-
|> Task.async_stream(fn {name, func} ->
30-
Telemetry.span(name, context, fn -> func.(config, now) end)
31-
end)
32-
|> Enum.flat_map(fn {:ok, instances} -> instances end)
33-
end)
22+
@instance_generators
23+
|> Task.async_stream(& &1.(config, now))
24+
|> Enum.flat_map(fn {:ok, instances} -> instances end)
3425
end
3526

3627
@impl CandidateGenerator

0 commit comments

Comments
 (0)