Error reporting to Vigil (sentry-elixir)

b6f7c30 · gmorell · 2026-12-02 06:52

10 files +50 -0
Message
{commit_body(@commit)}

Files changed

modified config/config.exs
+10 −0
@@ -109,6 +109,16 @@ config :logger, :default_formatter,
109 109 # Use Jason for JSON parsing in Phoenix
110 110 config :phoenix, :json_library, Jason
111 111
112 +# Error reporting through sentry-elixir, to Vigil (vigil.neiam.org). Inert
113 +# until runtime.exs sets a DSN from SENTRY_DSN: plug-pipeline errors
114 +# (Sentry.PlugCapture in the Endpoint), error logs and crashes
115 +# (CartosnapApp.Application attaches Sentry.LoggerHandler), Oban job errors,
116 +# and any Oban cron jobs as cron monitors.
117 +config :sentry,
118 + dsn: nil,
119 + enable_source_code_context: false,
120 + integrations: [oban: [capture_errors: true, cron: [enabled: true]]]
121 +
112 122 # Import environment specific config. This must remain at the bottom
113 123 # of this file so it overrides the configuration defined above.
114 124 import_config "#{config_env()}.exs"
modified config/runtime.exs
+15 −0
@@ -36,6 +36,21 @@ end
36 36 config :cartosnap_app, CartosnapAppWeb.Endpoint,
37 37 http: [port: String.to_integer(System.get_env("PORT", "4000"))]
38 38
39 +# Error reporting (config.exs). Blank counts as unset, so an empty
40 +# `sentry_dsn` in the Secret leaves reporting off.
41 +if config_env() == :prod do
42 + case System.get_env("SENTRY_DSN", "") |> String.trim() do
43 + "" ->
44 + :ok
45 +
46 + dsn ->
47 + config :sentry,
48 + dsn: dsn,
49 + environment_name: System.get_env("SENTRY_ENVIRONMENT", "production"),
50 + release: "cartosnap_app@" <> to_string(Application.spec(:cartosnap_app, :vsn) || "dev")
51 + end
52 +end
53 +
39 54 if config_env() == :dev do
40 55 # Reload browser tabs when matching files change.
41 56 config :cartosnap_app, CartosnapAppWeb.Endpoint,
modified lib/cartosnap_app/application.ex
+13 −0
@@ -7,6 +7,7 @@ defmodule CartosnapApp.Application do
7 7
8 8 @impl true
9 9 def start(_type, _args) do
10 + attach_sentry()
10 11 topologies = Application.get_env(:libcluster, :topologies, [])
11 12
12 13 children = [
@@ -36,6 +37,18 @@ defmodule CartosnapApp.Application do
36 37 defp cluster_child(topologies),
37 38 do: {Cluster.Supervisor, [topologies, [name: CartosnapApp.ClusterSupervisor]]}
38 39
40 + # Crashes and error logs to Vigil, when a SENTRY_DSN is configured
41 + # (config/runtime.exs); without one, nothing is attached.
42 + defp attach_sentry do
43 + if Sentry.Config.dsn() do
44 + :logger.add_handler(:sentry_handler, Sentry.LoggerHandler, %{
45 + config: %{metadata: [:request_id], capture_log_messages: false, level: :error}
46 + })
47 + end
48 +
49 + :ok
50 + end
51 +
39 52 # Tell Phoenix to update the endpoint configuration
40 53 # whenever the application is updated.
41 54 @impl true
modified lib/cartosnap_app_web/endpoint.ex
+7 −0
@@ -1,4 +1,7 @@
1 1 defmodule CartosnapAppWeb.Endpoint do
2 + # Reports errors raised in the plug pipeline when a SENTRY_DSN is set;
3 + # before Phoenix.Endpoint, as sentry-elixir asks.
4 + use Sentry.PlugCapture
2 5 use Phoenix.Endpoint, otp_app: :cartosnap_app
3 6
4 7 # The session will be stored in the cookie and signed,
@@ -59,6 +62,10 @@ defmodule CartosnapAppWeb.Endpoint do
59 62 pass: ["*/*"],
60 63 json_decoder: Phoenix.json_library()
61 64
65 + # Request details on reported errors (sentry-elixir scrubs passwords,
66 + # secrets, cookies and the Authorization header).
67 + plug Sentry.PlugContext
68 +
62 69 plug Plug.MethodOverride
63 70 plug Plug.Head
64 71 plug Plug.Session, @session_options
modified mix.exs
+3 −0
@@ -86,6 +86,9 @@ defmodule CartosnapApp.MixProject do
86 86 # The image pipeline: uploads are resized in the background by
87 87 # CartosnapApp.Workers.ProcessImage, queued in Postgres.
88 88 {:oban, "~> 2.20"},
89 + # Error reporting to Vigil (vigil.neiam.org), Sentry's protocol.
90 + # Inert unless SENTRY_DSN is set (config/runtime.exs).
91 + {:sentry, "~> 14.1"},
89 92 {:mogrify, "~> 0.9"},
90 93 {:blurhash, "~> 2.0"},
91 94 {:nextexif, "~> 0.1.1"}
modified mix.lock
+2 −0
@@ -35,6 +35,7 @@
35 35 "neiam_auth": {:git, "https://gg.neiam.co/neiam/neiam_auth.git", "f58a6a74e89f26f91f51dc5bc8977c7a4d9bc47e", [tag: "v0.4.0"]},
36 36 "nextexif": {:hex, :nextexif, "0.1.2", "4319f282feefe7928e1db5264e12e55cf27fc3681054fbdcc9f82178be5351ad", [:mix], [], "hexpm", "ce9a73d82bf61ceeb9dbb2014df2291e04deb3c3c2463e4f4c260875c43e2735"},
37 37 "nimble_options": {:hex, :nimble_options, "1.2.0", "73e5c5fecb08e59f390e0f59c2320b585d72470dbdd9230a469e06881b9dd4a8", [:mix], [], "hexpm", "3a784a75ef9e407619c8c9e98239b1acd29216deb737044a8c1063e2671ce6d9"},
38 + "nimble_ownership": {:hex, :nimble_ownership, "1.0.2", "fa8a6f2d8c592ad4d79b2ca617473c6aefd5869abfa02563a77682038bf916cf", [:mix], [], "hexpm", "098af64e1f6f8609c6672127cfe9e9590a5d3fcdd82bc17a377b8692fd81a879"},
38 39 "nimble_pool": {:hex, :nimble_pool, "1.2.0", "7f7e19c4fc7e960ffd405b0bcaec73e29a96e249a806b386f57e18192f24fa4f", [:mix], [], "hexpm", "bc442e72578c21842589fa8e5886b6175fa5245fdbbad35fc08db277ac2b2c0d"},
39 40 "oban": {:hex, :oban, "2.24.2", "2309cbe71f096cfb00ec8102a0beaaaaf54b2f449c63ce6cc9ce1fa46ea8fc4b", [:mix], [{:ecto_sql, "~> 3.10", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:ecto_sqlite3, "~> 0.9", [hex: :ecto_sqlite3, repo: "hexpm", optional: true]}, {:igniter, "~> 0.5", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:myxql, "~> 0.7", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.20", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 1.3", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "605a3b61d554ab416e0cf462b5ea060f7d19ae3dbf1516ec6b5ee30aeb1a5d0b"},
40 41 "oidcc": {:hex, :oidcc, "3.9.2", "6f3e6e574e8d01dcc63a27b87e0790bbe6700bea82b4cf74dbe52ba26378da15", [:mix, :rebar3], [{:igniter, ">= 0.6.3 and < 0.9.0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jose, "~> 1.11", [hex: :jose, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.2", [hex: :telemetry, repo: "hexpm", optional: false]}, {:telemetry_registry, "~> 0.3.1", [hex: :telemetry_registry, repo: "hexpm", optional: false]}], "hexpm", "e469213a2518904e805ff4f8325a405ac740a74a381e711968d32636c10d9c9b"},
@@ -51,6 +52,7 @@
51 52 "postgrex": {:hex, :postgrex, "0.23.0", "f106e1429559f0db8799c250279ee5fa16e364a39380cd9523e725df3625b235", [:mix], [{:db_connection, "~> 2.9", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "f001ab3fd56f5ef2b8b3cd4a512005614fcaeccca068ddb29e57d338a7f104ec"},
52 53 "ranch": {:hex, :ranch, "2.4.0", "1552c523119cfb8dda7f171f02f664805ab08d89d2a18adfa8992676184d767a", [:make, :rebar3], [], "hexpm", "64d98b8c61d39b7b9a2e2cf92ae659b8623a69766f415ae13dc726864ec04ab9"},
53 54 "req": {:hex, :req, "0.7.5", "0c3293cbf7717aba20b1b1b3ea13fe8d3fdf6f1557490f390c3f1ef6dd9db955", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:finch, "~> 0.21", [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", "576853c4bf403faa3c1fa5d093e0759227083b78f8a6864c67d62c0a9c45514d"},
55 + "sentry": {:hex, :sentry, "14.1.0", "7299ad220029c7d972ef7fea571fbe0a910655fe3f0b30aef8681b1730581359", [:mix], [{:finch, "~> 0.21", [hex: :finch, repo: "hexpm", optional: true]}, {:hackney, ">= 1.8.0 and < 5.0.0", [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, "~> 1.0", [hex: :nimble_ownership, repo: "hexpm", optional: false]}, {:opentelemetry, ">= 0.0.0", [hex: :opentelemetry, repo: "hexpm", optional: true]}, {:opentelemetry_api, ">= 0.0.0", [hex: :opentelemetry_api, repo: "hexpm", optional: true]}, {:opentelemetry_exporter, ">= 0.0.0", [hex: :opentelemetry_exporter, repo: "hexpm", optional: true]}, {:opentelemetry_semantic_conventions, ">= 0.0.0", [hex: :opentelemetry_semantic_conventions, repo: "hexpm", optional: true]}, {: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]}, {:telemetry_poller, "~> 0.5 or ~> 1.0", [hex: :telemetry_poller, repo: "hexpm", optional: true]}], "hexpm", "f2ebc73fac06d0595347a4bb474dcb9230783dcd6cfcfe62ac10fe243d33743d"},
54 56 "swoosh": {:hex, :swoosh, "1.30.0", "a0904169dce7777d4decb80fb01b51eb317e6d140e9f6f00a8e2562426ae06e8", [: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.0 and < 5.0.0", [hex: :hackney, repo: "hexpm", optional: true]}, {:idna, ">= 6.0.0 and < 9.0.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", "d1b553f5264ae39fb299e0da12e01e33aaba49c2509757065ca3aef06e659b0c"},
55 57 "tailwind": {:hex, :tailwind, "0.5.2", "d8bc230361fd3e14b495043c364aefddfac2ad4bf2eada380f458e9a15cb2e20", [:mix], [], "hexpm", "e0e5fd9799fb9231b97e52ce074d9ff509043d1946713a71fbc608e81eff7e66"},
56 58 "telemetry": {:hex, :telemetry, "1.4.3", "d0333fa869361e6833d6ff8e806ff4d8553fe1332fcce0af86c7381951a1dc2f", [:rebar3], [], "hexpm", "17a63581cf2e832a238287f5fe6811e8ca1f333249f1376ad653164a3c4770d4"},

Parents: 89d68a0