Skip to content

Commit 3e9ae28

Browse files
committed
add send_test_event mix task
1 parent f825916 commit 3e9ae28

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
defmodule Mix.Tasks.Sentry.SendTestEvent do
2+
use Mix.Task
3+
4+
@shortdoc "Attempts to send a test event to check Sentry configuration"
5+
6+
def run(_args) do
7+
Application.ensure_all_started(:sentry)
8+
{endpoint, public_key, secret_key} = case Application.fetch_env(:sentry, :dsn) do
9+
{:ok, dsn} when is_binary(dsn) -> Sentry.Client.parse_dsn!(dsn)
10+
_ ->
11+
Mix.raise "Sentry DSN is not configured in :sentry, :dsn"
12+
end
13+
14+
included_environments = case Application.fetch_env(:sentry, :included_environments) do
15+
{:ok, envs} when is_list(envs) -> envs
16+
_ ->
17+
Mix.raise "Sentry included_environments is not configured in :sentry, :included_environments"
18+
end
19+
20+
environment_name = Application.get_env(:sentry, :environment_name)
21+
Mix.shell.info "Client configuration:"
22+
Mix.shell.info "server: #{endpoint}"
23+
Mix.shell.info "public_key: #{public_key}"
24+
Mix.shell.info "secret_key: #{secret_key}"
25+
Mix.shell.info "included_environments: #{inspect included_environments}"
26+
Mix.shell.info "current environment_name: #{inspect environment_name}\n"
27+
28+
maybe_send_event(environment_name, included_environments)
29+
end
30+
31+
def maybe_send_event(env_name, included_envs) do
32+
if env_name in included_envs do
33+
Mix.shell.info "Sending test event!"
34+
Sentry.capture_exception(RuntimeError.exception("Testing sending Sentry event"))
35+
else
36+
Mix.shell.info "#{inspect env_name} is not in #{inspect included_envs} so no test event will be sent"
37+
end
38+
end
39+
end

0 commit comments

Comments
 (0)