Skip to content

Commit

Permalink
Merge pull request #982 from OpenFn/sentry_releases
Browse files Browse the repository at this point in the history
Sentry releases
  • Loading branch information
taylordowns2000 authored Jul 27, 2023
2 parents 0a9eeb2 + 6e150a7 commit 4b6b546
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
31 changes: 24 additions & 7 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,6 @@ config :lightning,
System.get_env("INIT_PROJECT_FOR_NEW_USER", "false")
|> String.to_atom()

# If you've booted up with a SENTRY_DSN environment variable, use Sentry!
config :sentry,
filter: Lightning.SentryEventFilter,
environment_name: config_env(),
included_environments:
if(System.get_env("SENTRY_DSN"), do: [config_env()], else: [])

# To actually send emails you need to configure the mailer to use a real
# adapter. You may configure the swoosh api client of your choice. We
# automatically configure Mailgun if an API key has been provided. See
Expand Down Expand Up @@ -248,3 +241,27 @@ if config_env() == :test do
config :lightning, Lightning.Repo,
pool_size: :erlang.system_info(:schedulers_online) + 4
end

release =
case Application.get_env(:lightning, :image_info) do
[image_tag: image_tag, branch: _branch, commit: commit] ->
if Enum.member?(["edge", "latest"], image_tag),
do: commit,
else: image_tag

_other ->
"mix-v#{elem(:application.get_key(:lightning, :vsn), 1)}"
end

config :sentry,
filter: Lightning.SentryEventFilter,
environment_name: config_env(),
tags: %{
host: Application.get_env(:lightning, LightningWeb.Endpoint)[:url][:host]
},
# If you've booted up with a SENTRY_DSN environment variable, use Sentry!
included_environments:
if(System.get_env("SENTRY_DSN"), do: [config_env()], else: []),
release: release,
enable_source_code_context: true,
root_source_code_path: File.cwd!()
10 changes: 8 additions & 2 deletions lib/lightning_web/live/components/common.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ defmodule LightningWeb.Components.Common do
"Docker image tag found: '#{image}' tagged release build from #{commit}",
:release}

# If running in docker and tag doesn't match :vsn, display :vsn and warning.
# If running in docker and tag doesn't match :vsn, display image tag.
image != nil and image != vsn and image != "edge" ->
{image,
"Detected image tag that does not match application version #{vsn}; image tag '#{image}' built from #{commit}",
:warn}

# If running in docker and tag doesn't match :vsn, display commit.
image != nil and image != vsn ->
{commit,
"Warning: detected image tag that does not match application version #{vsn}; image tag '#{image}' built from #{commit}",
"Detected image tag that does not match application version #{vsn}; image tag '#{image}' built from #{commit}",
:warn}

true ->
Expand Down
2 changes: 1 addition & 1 deletion test/lightning_web/live/components/common_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ defmodule LightningWeb.Components.CommonTest do
"M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z"

assert html =~
"Warning: detected image tag that does not match application version"
"Detected image tag that does not match application version"

assert html =~ "v#{elem(:application.get_key(:lightning, :vsn), 1)}"
end
Expand Down

0 comments on commit 4b6b546

Please sign in to comment.