Add Sentry error tracking
1239e9a · gmorell · 2026-06-26 15:26
Message
{commit_body(@commit)}
Files changed
modified
config/config.exs
+8
−0
@@ -248,6 +248,14 @@ config :logger, :default_formatter,
| 248 | 248 | # Use Jason for JSON parsing in Phoenix |
| 249 | 249 | config :phoenix, :json_library, Jason |
| 250 | 250 | |
| 251 | +# Sentry error tracking. The DSN is wired from SENTRY_DSN in | |
| 252 | +# runtime.exs; when unset (dev/test) Sentry no-ops. Source context lets | |
| 253 | +# stacktraces show the offending lines. | |
| 254 | +config :sentry, | |
| 255 | + environment_name: config_env(), | |
| 256 | + enable_source_code_context: true, | |
| 257 | + root_source_code_paths: [File.cwd!()] | |
| 258 | + | |
| 251 | 259 | # Import environment specific config. This must remain at the bottom |
| 252 | 260 | # of this file so it overrides the configuration defined above. |
| 253 | 261 | import_config "#{config_env()}.exs" |
modified
config/runtime.exs
+3
−0
@@ -158,6 +158,9 @@ if config_env() == :prod do
| 158 | 158 | config :git_gud, :default_actions_url, actions_url |
| 159 | 159 | end |
| 160 | 160 | |
| 161 | + # Sentry error tracking. Unset -> Sentry no-ops. | |
| 162 | + config :sentry, dsn: System.get_env("SENTRY_DSN") | |
| 163 | + | |
| 161 | 164 | # The secret key base is used to sign/encrypt cookies and other secrets. |
| 162 | 165 | # A default value is used in config/dev.exs and config/test.exs but you |
| 163 | 166 | # want to use a different value for prod and you most likely don't want |
modified
lib/git_gud/application.ex
+7
−0
@@ -7,6 +7,13 @@ defmodule GitGud.Application do
| 7 | 7 | |
| 8 | 8 | @impl true |
| 9 | 9 | def start(_type, _args) do |
| 10 | + # Route error-level logs + process crash reports (incl. LiveView and | |
| 11 | + # GenServer terminations) to Sentry. No-ops when SENTRY_DSN is unset. | |
| 12 | + :logger.add_handler(:sentry_handler, Sentry.LoggerHandler, %{ | |
| 13 | + level: :error, | |
| 14 | + config: %{metadata: [:file, :line], capture_log_messages: true} | |
| 15 | + }) | |
| 16 | + | |
| 10 | 17 | topologies = Application.get_env(:libcluster, :topologies, []) |
| 11 | 18 | |
| 12 | 19 | children = |
modified
lib/git_gud_web/endpoint.ex
+2
−0
@@ -1,5 +1,7 @@
| 1 | 1 | defmodule GitGudWeb.Endpoint do |
| 2 | 2 | use Phoenix.Endpoint, otp_app: :git_gud |
| 3 | + # Captures crashes during request handling and reports them to Sentry. | |
| 4 | + use Sentry.PlugCapture | |
| 3 | 5 | |
| 4 | 6 | # The session will be stored in the cookie and signed, |
| 5 | 7 | # this means its contents can be read but not tampered with. |
modified
mix.exs
+3
−0
@@ -66,6 +66,9 @@ defmodule GitGud.MixProject do
| 66 | 66 | # log instead of being silently dropped. |
| 67 | 67 | {:gen_smtp, "~> 1.2"}, |
| 68 | 68 | {:req, "~> 0.5"}, |
| 69 | + # Error tracking. Uses the hackney client (already a dep) and | |
| 70 | + # captures crash reports via a :logger handler (see application.ex). | |
| 71 | + {:sentry, "~> 10.8"}, | |
| 69 | 72 | {:telemetry_metrics, "~> 1.0"}, |
| 70 | 73 | {:telemetry_poller, "~> 1.0"}, |
| 71 | 74 | {:gettext, "~> 1.0"}, |
modified
mix.lock
+2
−0
@@ -40,6 +40,7 @@
| 40 | 40 | "mint": {:hex, :mint, "1.8.0", "b964eaf4416f2dee2ba88968d52239fca5621b0402b9c95f55a08eb9d74803e9", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1 or ~> 0.2.0 or ~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "f3c572c11355eccf00f22275e9b42463bc17bd28db13be1e28f8e0bb4adbc849"}, |
| 41 | 41 | "nebulex": {:hex, :nebulex, "2.6.6", "677e27fcfa89eaa085d9509d5e066f305f98c1b2264ce6676eaca6fb08d4939e", [:mix], [{:decorator, "~> 1.4", [hex: :decorator, repo: "hexpm", optional: true]}, {:shards, "~> 1.1", [hex: :shards, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "8cbf531af6fe407383b6ba410a43a19319af47804929d8a8d1975a780b9952df"}, |
| 42 | 42 | "nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"}, |
| 43 | + "nimble_ownership": {:hex, :nimble_ownership, "1.0.2", "fa8a6f2d8c592ad4d79b2ca617473c6aefd5869abfa02563a77682038bf916cf", [:mix], [], "hexpm", "098af64e1f6f8609c6672127cfe9e9590a5d3fcdd82bc17a377b8692fd81a879"}, | |
| 43 | 44 | "nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"}, |
| 44 | 45 | "nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"}, |
| 45 | 46 | "nimble_totp": {:hex, :nimble_totp, "1.0.0", "79753bae6ce59fd7cacdb21501a1dbac249e53a51c4cd22b34fa8438ee067283", [:mix], [], "hexpm", "6ce5e4c068feecdb782e85b18237f86f66541523e6bad123e02ee1adbe48eda9"}, |
@@ -61,6 +62,7 @@
| 61 | 62 | "req": {:hex, :req, "0.5.17", "0096ddd5b0ed6f576a03dde4b158a0c727215b15d2795e59e0916c6971066ede", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.17", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "0b8bc6ffdfebbc07968e59d3ff96d52f2202d0536f10fef4dc11dc02a2a43e39"}, |
| 62 | 63 | "rustler": {:hex, :rustler, "0.37.3", "5f4e6634d43b26f0a69834dd1d3ed4e1710b022a053bf4a670220c9540c92602", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "a6872c6f53dcf00486d1e7f9e046e20e01bf1654bdacc4193016c2e8002b32a2"}, |
| 63 | 64 | "rustler_precompiled": {:hex, :rustler_precompiled, "0.9.0", "3a052eda09f3d2436364645cc1f13279cf95db310eb0c17b0d8f25484b233aa0", [:mix], [{:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "471d97315bd3bf7b64623418b3693eedd8e47de3d1cb79a0ac8f9da7d770d94c"}, |
| 65 | + "sentry": {:hex, :sentry, "10.10.0", "d058b635f3796947545c8057a42996f6dbefd12152da947209b56d16af41b161", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_ownership, "~> 0.3.0 or ~> 1.0", [hex: :nimble_ownership, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.6", [hex: :phoenix, repo: "hexpm", optional: true]}, {:phoenix_live_view, "~> 0.20 or ~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.6", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "7c7ddd3cfdd63fcee53b1e28f9a653037e6927b2b1dbd300b7aeee9687c7a8f6"}, | |
| 64 | 66 | "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"}, |
| 65 | 67 | "sweet_xml": {:hex, :sweet_xml, "0.7.5", "803a563113981aaac202a1dbd39771562d0ad31004ddbfc9b5090bdcd5605277", [:mix], [], "hexpm", "193b28a9b12891cae351d81a0cead165ffe67df1b73fe5866d10629f4faefb12"}, |
| 66 | 68 | "swoosh": {:hex, :swoosh, "1.25.2", "cd3e53b0391439395492e5dce8c22288733f22603e21136162d03cd153669be9", [:mix], [{:bandit, ">= 1.0.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:idna, "~> 6.0", [hex: :idna, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mua, "~> 0.2.3", [hex: :mua, repo: "hexpm", optional: true]}, {:multipart, "~> 0.4", [hex: :multipart, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:req, "~> 0.5.10 or ~> 0.6 or ~> 1.0", [hex: :req, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "0aecf65b2845f13f4d440e0945715432bbde2d815e2302adf7df549cd9bdafed"}, |
Parents: d41fffb