Skip to content

Commit 1dd8783

Browse files
committed
replace whitelist with allow list
1 parent 6c13340 commit 1dd8783

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ The full range of options is the following:
166166
| `sample_rate` | False | 1.0 | |
167167
| `send_result` | False | `:none` | You may want to set it to `:sync` if testing your Sentry integration. See "Testing with Sentry" |
168168
| `send_max_attempts` | False | 4 | |
169-
| `in_app_module_whitelist` | False | `[]` | |
169+
| `in_app_module_allow_list` | False | `[]` | |
170170
| `report_deps` | False | True | Will attempt to load Mix dependencies at compile time to report alongside events |
171171
| `enable_source_code_context` | False | False | |
172172
| `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"]`. |

lib/sentry/config.ex

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,36 @@ defmodule Sentry.Config do
136136
get_config(:context_lines, default: @default_context_lines, check_dsn: false)
137137
end
138138

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

144+
def in_app_module_allow_list do
145+
new_config = get_config(:in_app_module_allow_list, default: [], check_dsn: false)
146+
old_config = get_config(:in_app_module_whitelist, check_dsn: false)
147+
148+
cond do
149+
not is_nil(new_config) and not is_nil(old_config) ->
150+
raise ArgumentError, """
151+
:in_app_module_allow_list and :in_app_module_whitelist can't be configured at the \
152+
same time.
153+
154+
:in_app_module_whitelist is deprecated. Set :in_app_module_allow_list instead.
155+
"""
156+
157+
not is_nil(old_config) ->
158+
IO.warn(
159+
"Sentry.Config.in_app_module_whitelist/0 is deprecated. Use Sentry.Config.in_app_module_allow_list/0 instead."
160+
)
161+
162+
old_config
163+
164+
true ->
165+
new_config
166+
end
167+
end
168+
143169
def send_result do
144170
get_config(:send_result, default: @default_send_result, check_dsn: false)
145171
end

lib/sentry/event.ex

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule Sentry.Event do
55
66
### Configuration
77
8-
* `: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 `[]`.
8+
* `: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 `[]`.
99
* `:report_deps` - Flag for whether to include the loaded dependencies when reporting an error. Defaults to true.
1010
1111
"""
@@ -220,7 +220,7 @@ defmodule Sentry.Event do
220220

221221
@spec stacktrace_to_frames(Exception.stacktrace()) :: [map]
222222
def stacktrace_to_frames(stacktrace) do
223-
in_app_module_whitelist = Config.in_app_module_whitelist()
223+
in_app_module_allow_list = Config.in_app_module_allow_list()
224224

225225
stacktrace
226226
|> Enum.map(fn line ->
@@ -236,7 +236,7 @@ defmodule Sentry.Event do
236236
function: Exception.format_mfa(mod, function, arity),
237237
module: mod,
238238
lineno: line_number,
239-
in_app: is_in_app?(mod, in_app_module_whitelist),
239+
in_app: is_in_app?(mod, in_app_module_allow_list),
240240
vars: f_args
241241
}
242242
|> put_source_context(file, line_number)
@@ -284,17 +284,17 @@ defmodule Sentry.Event do
284284
defp arity_to_integer(arity) when is_list(arity), do: Enum.count(arity)
285285
defp arity_to_integer(arity) when is_integer(arity), do: arity
286286

287-
defp is_in_app?(nil, _in_app_whitelist), do: false
287+
defp is_in_app?(nil, _in_app_allow_list), do: false
288288
defp is_in_app?(_, []), do: false
289289

290-
defp is_in_app?(module, in_app_module_whitelist) do
290+
defp is_in_app?(module, in_app_module_allow_list) do
291291
split_modules = module_split(module)
292292

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

296-
count = Enum.count(whitelisted_split_modules)
297-
Enum.take(split_modules, count) == whitelisted_split_modules
296+
count = Enum.count(allowed_split_modules)
297+
Enum.take(split_modules, count) == allowed_split_modules
298298
end)
299299
end
300300

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ defmodule Sentry.Mixfile do
4242
{:plug_cowboy, "~> 2.3", optional: true},
4343
{:dialyxir, "~> 1.0", only: [:dev], runtime: false},
4444
{:ex_doc, "~> 0.23.0", only: :dev},
45-
{:bypass, "~> 1.0", only: [:test]},
45+
{:bypass, "~> 2.0", only: [:test]},
4646
{:phoenix, "~> 1.5", only: [:test]},
4747
{:phoenix_html, "~> 2.0", only: [:test]}
4848
]

test/event_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ defmodule Sentry.EventTest do
163163
end
164164

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

169169
event =

0 commit comments

Comments
 (0)