Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove redundant Sentry-disabling code #2139

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/src/components/v2/widget_tree_error_boundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class WidgetTreeErrorBoundary extends React.Component<Props, State> {
return;
}

if (getDataset().disableSentry) {
if (!getDataset().sentry) {
// Log via the server. (to Splunk, at time of writing.)
fetch("/v2/api/screen/log_frontend_error", {
method: "POST",
Expand Down
13 changes: 4 additions & 9 deletions assets/src/util/sentry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@ const captureException = (ex: unknown, options?: RavenOptions) => {

/**
* Initializes Sentry if the DSN is defined AND this client is running on
* a real production screen AND the URL does not contain the disable_sentry param.
* a real production screen.
*/
const initSentry = (appString: string) => {
const {
sentry: sentryDsn,
environmentName: env,
disableSentry,
} = getDataset();
// Note: passing an empty string as the DSN sets up a "no-op SDK" that captures errors and lets you call its methods,
// but does not actually log anything to the Sentry service.
const { sentry: sentryDsn, environmentName: env } = getDataset();

if (sentryDsn && isRealScreen() && !disableSentry) {
if (sentryDsn && isRealScreen()) {
Raven.config(sentryDsn, { environment: env }).install();

if (isOFM()) {
const today = new Date();
const hour = today.getHours();
Expand Down
13 changes: 4 additions & 9 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ unless config_env() == :test do
end

if config_env() == :prod do
config :sentry,
dsn: System.get_env("SENTRY_DSN"),
environment_name: eb_env_name

signs_ui_s3_bucket =
case eb_env_name do
"screens-prod" -> "mbta-signs"
Expand All @@ -33,20 +37,11 @@ if config_env() == :prod do
http: [:inet6, port: String.to_integer(System.get_env("PORT") || "4000")],
secret_key_base: System.get_env("SECRET_KEY_BASE")

sentry_dsn = System.get_env("SENTRY_DSN")

config :screens,
environment_name: eb_env_name,
signs_ui_s3_bucket: signs_ui_s3_bucket,
sentry_frontend_dsn: sentry_dsn,
screenplay_fullstory_org_id: System.get_env("SCREENPLAY_FULLSTORY_ORG_ID")

if sentry_dsn not in [nil, ""] do
config :sentry,
dsn: sentry_dsn,
environment_name: eb_env_name
end

config :screens, ScreensWeb.AuthManager, secret_key: System.get_env("SCREENS_AUTH_SECRET")

config :screens, Screens.ScreensByAlert.Memcache,
Expand Down
3 changes: 1 addition & 2 deletions lib/screens_web/controllers/screen_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ defmodule ScreensWeb.ScreenController do
%Screen{app_id: app_id} ->
conn
|> assign(:app_id, app_id)
|> assign(:sentry_frontend_dsn, Application.get_env(:screens, :sentry_frontend_dsn))
|> assign(:sentry_dsn, if(params["disable_sentry"], do: nil, else: Sentry.get_dsn()))
|> assign(:is_real_screen, match?(%{"is_real_screen" => "true"}, params))
|> assign(:requestor, params["requestor"])
|> assign(:disable_sentry, params["disable_sentry"])
|> render("index.html")

nil ->
Expand Down
3 changes: 1 addition & 2 deletions lib/screens_web/controllers/v2/screen_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,11 @@ defmodule ScreensWeb.V2.ScreenController do
refresh_rate: refresh_rate,
audio_readout_interval: Parameters.get_audio_readout_interval(app_id),
audio_interval_offset_seconds: Parameters.get_audio_interval_offset_seconds(config),
sentry_frontend_dsn: Application.get_env(:screens, :sentry_frontend_dsn),
sentry_dsn: if(params["disable_sentry"], do: nil, else: Sentry.get_dsn()),
refresh_rate_offset: calculate_refresh_rate_offset(screen_id, refresh_rate),
is_real_screen: match?(%{"is_real_screen" => "true"}, params),
screen_side: screen_side(params),
requestor: params["requestor"],
disable_sentry: params["disable_sentry"],
rotation_index: rotation_index(params),
triptych_pane: triptych_pane(params),
is_pending: false
Expand Down
5 changes: 1 addition & 4 deletions lib/screens_web/templates/screen/index.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@
data-environment-name="<%= @environment_name %>"
data-is-real-screen="<%= @is_real_screen %>"
data-requestor="<%= @requestor %>"
data-disable-sentry="<%= @disable_sentry %>"
<%= if record_sentry?() do %>
data-sentry="<%= @sentry_frontend_dsn %>"
<% end %>
data-sentry="<%= @sentry_dsn %>"
></div>
5 changes: 1 addition & 4 deletions lib/screens_web/templates/v2/screen/index.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
data-refresh-rate-offset="<%= @refresh_rate_offset %>"
data-is-real-screen="<%= @is_real_screen %>"
data-is-pending="<%= @is_pending %>"
data-sentry="<%= @sentry_dsn %>"
<%= if not is_nil(@screen_side) do %>
data-screen-side="<%= @screen_side %>"
<% end %>
<%= if record_sentry?() do %>
data-sentry="<%= @sentry_frontend_dsn %>"
<% end %>
<%= if not is_nil(@rotation_index) do %>
data-rotation-index="<%= @rotation_index %>"
<% end %>
Expand All @@ -24,5 +22,4 @@
data-screenplay-fullstory-org-id="<%= assigns[:screenplay_fullstory_org_id] %>"
<% end %>
data-requestor="<%= @requestor %>"
data-disable-sentry="<%= @disable_sentry %>"
></div>
2 changes: 0 additions & 2 deletions lib/screens_web/views/screen_view.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
defmodule ScreensWeb.ScreenView do
use ScreensWeb, :view

def record_sentry?, do: Application.get_env(:screens, :record_sentry, false)
end
2 changes: 0 additions & 2 deletions lib/screens_web/views/v2/screen_view.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
defmodule ScreensWeb.V2.ScreenView do
use ScreensWeb, :view

def record_sentry?, do: Application.get_env(:screens, :record_sentry, false)
end
Loading