Add telemetry for scrobble rule application

This commit is contained in:
Claudio Ortolina
2025-09-28 08:25:01 +03:00
parent ee6cfaef79
commit 5f5b66d037
2 changed files with 29 additions and 12 deletions
+22 -12
View File
@@ -336,12 +336,17 @@ defmodule MusicLibrary.ScrobbleRules do
"""
def apply_all_rules do
list_enabled_rules()
|> Enum.map(fn rule ->
case apply_rule(rule) do
{:ok, count} -> {:ok, {rule.type, rule.match_value, count}}
{:error, reason} -> {:error, {rule.type, rule.match_value, reason}}
end
:telemetry.span([:music_library, :scrobble_rules, :apply_all_rules], %{}, fn ->
result =
list_enabled_rules()
|> Enum.map(fn rule ->
case apply_rule(rule) do
{:ok, count} -> {:ok, {rule.type, rule.match_value, count}}
{:error, reason} -> {:error, {rule.type, rule.match_value, reason}}
end
end)
{result, %{scrobble_track_count: :all}}
end)
end
@@ -362,12 +367,17 @@ defmodule MusicLibrary.ScrobbleRules do
end
def apply_all_rules(tracks) do
list_enabled_rules()
|> Enum.map(fn rule ->
case apply_rule(rule, tracks) do
{:ok, count} -> {:ok, {rule.type, rule.match_value, count}}
{:error, reason} -> {:error, {rule.type, rule.match_value, reason}}
end
:telemetry.span([:music_library, :scrobble_rules, :apply_all_rules], %{}, fn ->
result =
list_enabled_rules()
|> Enum.map(fn rule ->
case apply_rule(rule, tracks) do
{:ok, count} -> {:ok, {rule.type, rule.match_value, count}}
{:error, reason} -> {:error, {rule.type, rule.match_value, reason}}
end
end)
{result, %{scrobble_track_count: Enum.count(tracks)}}
end)
end
+7
View File
@@ -88,6 +88,13 @@ defmodule MusicLibraryWeb.Telemetry do
reporter_options: [nav: "Assets"]
),
# Scrobble Rules
summary("music_library.scrobble_rules.apply_all_rules.stop.duration",
unit: {:native, :millisecond},
tags: [:scrobble_track_count],
reporter_options: [nav: "Scrobble Rules"]
),
# VM Metrics
summary("vm.memory.total", unit: {:byte, :megabyte}),
summary("vm.total_run_queue_lengths.total"),