Skip to content

Commit

Permalink
Merge pull request #450 from getsentry/deprecate-whitelist
Browse files Browse the repository at this point in the history
replace whitelist with allow list
  • Loading branch information
mitchellhenke authored Jan 10, 2021
2 parents 6c13340 + 1de5b9e commit 7a1ba52
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## next release
* Deprecate `Sentry.Config.in_app_module_whitelist` in favor of `Sentry.Config.in_app_module_allow_list` (#450)

## 8.0.4 (2020-11-16)

* Do not read dsn config at compile time (#441)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ The full range of options is the following:
| `sample_rate` | False | 1.0 | |
| `send_result` | False | `:none` | You may want to set it to `:sync` if testing your Sentry integration. See "Testing with Sentry" |
| `send_max_attempts` | False | 4 | |
| `in_app_module_whitelist` | False | `[]` | |
| `in_app_module_allow_list` | False | `[]` | |
| `report_deps` | False | True | Will attempt to load Mix dependencies at compile time to report alongside events |
| `enable_source_code_context` | False | False | |
| `root_source_code_paths` | Required if `enable_source_code_context` is enabled | | Should usually be set to `[File.cwd!()]`. For umbrella applications you should list all your applications paths in this list (e.g. `["#{File.cwd!()}/apps/app_1", "#{File.cwd!()}/apps/app_2"]`. |
Expand Down
26 changes: 26 additions & 0 deletions lib/sentry/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,36 @@ defmodule Sentry.Config do
get_config(:context_lines, default: @default_context_lines, check_dsn: false)
end

@deprecated "Use Sentry.Config.in_app_module_allow_list/0 instead."
def in_app_module_whitelist do
get_config(:in_app_module_whitelist, default: [], check_dsn: false)
end

def in_app_module_allow_list do
new_config = get_config(:in_app_module_allow_list, default: [], check_dsn: false)
old_config = get_config(:in_app_module_whitelist, check_dsn: false)

cond do
not is_nil(new_config) and not is_nil(old_config) ->
raise ArgumentError, """
:in_app_module_allow_list and :in_app_module_whitelist can't be configured at the \
same time.
:in_app_module_whitelist is deprecated. Set :in_app_module_allow_list instead.
"""

not is_nil(old_config) ->
IO.warn(
"Sentry.Config.in_app_module_whitelist/0 is deprecated. Use Sentry.Config.in_app_module_allow_list/0 instead."
)

old_config

true ->
new_config
end
end

def send_result do
get_config(:send_result, default: @default_send_result, check_dsn: false)
end
Expand Down
18 changes: 9 additions & 9 deletions lib/sentry/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Sentry.Event do
### Configuration
* `:in_app_module_whitelist` - Expects a list of modules that is used to distinguish among stacktrace frames that belong to your app and ones that are part of libraries or core Elixir. This is used to better display the significant part of stacktraces. The logic is greedy, so if your app's root module is `MyApp` and your setting is `[MyApp]`, that module as well as any submodules like `MyApp.Submodule` would be considered part of your app. Defaults to `[]`.
* `:in_app_module_allow_list` - Expects a list of modules that is used to distinguish among stacktrace frames that belong to your app and ones that are part of libraries or core Elixir. This is used to better display the significant part of stacktraces. The logic is greedy, so if your app's root module is `MyApp` and your setting is `[MyApp]`, that module as well as any submodules like `MyApp.Submodule` would be considered part of your app. Defaults to `[]`.
* `:report_deps` - Flag for whether to include the loaded dependencies when reporting an error. Defaults to true.
"""
Expand Down Expand Up @@ -220,7 +220,7 @@ defmodule Sentry.Event do

@spec stacktrace_to_frames(Exception.stacktrace()) :: [map]
def stacktrace_to_frames(stacktrace) do
in_app_module_whitelist = Config.in_app_module_whitelist()
in_app_module_allow_list = Config.in_app_module_allow_list()

stacktrace
|> Enum.map(fn line ->
Expand All @@ -236,7 +236,7 @@ defmodule Sentry.Event do
function: Exception.format_mfa(mod, function, arity),
module: mod,
lineno: line_number,
in_app: is_in_app?(mod, in_app_module_whitelist),
in_app: is_in_app?(mod, in_app_module_allow_list),
vars: f_args
}
|> put_source_context(file, line_number)
Expand Down Expand Up @@ -284,17 +284,17 @@ defmodule Sentry.Event do
defp arity_to_integer(arity) when is_list(arity), do: Enum.count(arity)
defp arity_to_integer(arity) when is_integer(arity), do: arity

defp is_in_app?(nil, _in_app_whitelist), do: false
defp is_in_app?(nil, _in_app_allow_list), do: false
defp is_in_app?(_, []), do: false

defp is_in_app?(module, in_app_module_whitelist) do
defp is_in_app?(module, in_app_module_allow_list) do
split_modules = module_split(module)

Enum.any?(in_app_module_whitelist, fn module ->
whitelisted_split_modules = module_split(module)
Enum.any?(in_app_module_allow_list, fn module ->
allowed_split_modules = module_split(module)

count = Enum.count(whitelisted_split_modules)
Enum.take(split_modules, count) == whitelisted_split_modules
count = Enum.count(allowed_split_modules)
Enum.take(split_modules, count) == allowed_split_modules
end)
end

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ defmodule Sentry.Mixfile do
{:plug_cowboy, "~> 2.3", optional: true},
{:dialyxir, "~> 1.0", only: [:dev], runtime: false},
{:ex_doc, "~> 0.23.0", only: :dev},
{:bypass, "~> 1.0", only: [:test]},
{:bypass, "~> 2.0", only: [:test]},
{:phoenix, "~> 1.5", only: [:test]},
{:phoenix_html, "~> 2.0", only: [:test]}
]
Expand Down
2 changes: 1 addition & 1 deletion test/event_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ defmodule Sentry.EventTest do
end

test "sets app_frame to true when configured" do
modify_env(:sentry, in_app_module_whitelist: [Sentry, :random, Sentry.Submodule])
modify_env(:sentry, in_app_module_allow_list: [Sentry, :random, Sentry.Submodule])
exception = RuntimeError.exception("error")

event =
Expand Down

0 comments on commit 7a1ba52

Please sign in to comment.