From 97f4267c5eeeb356dcb3e9cbcaa045bac47b4890 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Fri, 6 Mar 2026 20:27:58 +0000 Subject: [PATCH] Add telemetry for Markdown rendering --- lib/music_library_web/markdown.ex | 15 ++++++++++++--- lib/music_library_web/telemetry.ex | 6 ++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/music_library_web/markdown.ex b/lib/music_library_web/markdown.ex index 28f23535..9b206373 100644 --- a/lib/music_library_web/markdown.ex +++ b/lib/music_library_web/markdown.ex @@ -14,9 +14,18 @@ defmodule MusicLibraryWeb.Markdown do """ @spec to_html(String.t() | nil) :: String.t() def to_html(markdown_text) when is_binary(markdown_text) do - markdown_text - |> process_double_bracket_links() - |> Earmark.as_html!(%Earmark.Options{gfm: true}) + :telemetry.span( + [:markdown, :to_html], + %{}, + fn -> + result = + markdown_text + |> process_double_bracket_links() + |> Earmark.as_html!(%Earmark.Options{gfm: true}) + + {result, %{}} + end + ) end def to_html(nil), do: "" diff --git a/lib/music_library_web/telemetry.ex b/lib/music_library_web/telemetry.ex index f6080f0c..00166bc8 100644 --- a/lib/music_library_web/telemetry.ex +++ b/lib/music_library_web/telemetry.ex @@ -151,6 +151,12 @@ defmodule MusicLibraryWeb.Telemetry do reporter_options: [nav: "LiveView"] ), + # Markdown Processing Metrics + summary("markdown.to_html.stop.duration", + unit: {:native, :millisecond}, + reporter_options: [nav: "Markdown"] + ), + # VM Metrics summary("vm.memory.total", unit: {:byte, :megabyte}), summary("vm.total_run_queue_lengths.total"),