Sentry: release test fn + browser JS SDK
bb65d2b · gmorell · 2026-06-26 19:38
Message
{commit_body(@commit)}
Files changed
modified
lib/git_gud/release.ex
+23
−0
@@ -80,6 +80,29 @@ defmodule GitGud.Release do
| 80 | 80 | :ok |
| 81 | 81 | end |
| 82 | 82 | |
| 83 | + @doc """ | |
| 84 | + Send a test event to Sentry to verify the DSN + integration: | |
| 85 | + | |
| 86 | + kubectl -n git-gud exec deployment/git-gud -- \\ | |
| 87 | + bin/git_gud eval 'GitGud.Release.sentry_test()' | |
| 88 | + | |
| 89 | + Sends synchronously (`result: :sync`) so the eval node doesn't exit | |
| 90 | + before delivery. Returns `{:ok, id}` on success, `{:error, _}` on a | |
| 91 | + transport failure, or `:ignored` when no DSN is configured. | |
| 92 | + """ | |
| 93 | + def sentry_test do | |
| 94 | + {:ok, _} = Application.ensure_all_started(:sentry) | |
| 95 | + | |
| 96 | + result = | |
| 97 | + Sentry.capture_message("git_gud Sentry test event (Release.sentry_test/0)", | |
| 98 | + level: :error, | |
| 99 | + result: :sync | |
| 100 | + ) | |
| 101 | + | |
| 102 | + IO.inspect(result, label: "sentry_test") | |
| 103 | + result | |
| 104 | + end | |
| 105 | + | |
| 83 | 106 | defp repos do |
| 84 | 107 | Application.fetch_env!(@app, :ecto_repos) |
| 85 | 108 | end |
modified
lib/git_gud_web/components/layouts.ex
+6
−0
@@ -10,6 +10,12 @@ defmodule GitGudWeb.Layouts do
| 10 | 10 | |
| 11 | 11 | embed_templates "layouts/*" |
| 12 | 12 | |
| 13 | + @doc false | |
| 14 | + # Client-side Sentry DSN (same as the server's). nil -> the browser | |
| 15 | + # SDK isn't loaded (dev/test). Safe to expose; the DSN is a public, | |
| 16 | + # write-only ingestion key. | |
| 17 | + def sentry_dsn, do: Application.get_env(:sentry, :dsn) | |
| 18 | + | |
| 13 | 19 | @doc """ |
| 14 | 20 | Renders the app shell. |
| 15 | 21 |
modified
lib/git_gud_web/components/layouts/root.html.heex
+13
−0
@@ -8,6 +8,19 @@
| 8 | 8 | {assigns[:page_title]} |
| 9 | 9 | </.live_title> |
| 10 | 10 | <link phx-track-static rel="stylesheet" href={~p"/assets/css/app.css"} /> |
| 11 | + <%= if sentry_dsn() do %> | |
| 12 | + <meta name="sentry-dsn" content={sentry_dsn()} /> | |
| 13 | + <script src="https://browser.sentry-cdn.com/8.55.0/bundle.min.js" crossorigin="anonymous"> | |
| 14 | + </script> | |
| 15 | + <script> | |
| 16 | + if (window.Sentry) { | |
| 17 | + Sentry.init({ | |
| 18 | + dsn: document.querySelector('meta[name="sentry-dsn"]').content, | |
| 19 | + environment: "production" | |
| 20 | + }); | |
| 21 | + } | |
| 22 | + </script> | |
| 23 | + <% end %> | |
| 11 | 24 | <script defer phx-track-static type="text/javascript" src={~p"/assets/js/app.js"}> |
| 12 | 25 | </script> |
| 13 | 26 | <script> |
Parents: 10d3ddc