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

Better in app module allow list default #854

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions lib/sentry/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ defmodule Sentry.Application do
config = Config.validate!()
:ok = Config.persist(config)

Config.put_config(
:in_app_module_allow_list,
Config.in_app_module_allow_list() ++ resolve_in_app_module_allow_list()
)

http_client = Keyword.fetch!(config, :client)

maybe_http_client_spec =
Expand Down Expand Up @@ -71,4 +76,13 @@ defmodule Sentry.Application do
Sentry.Integrations.Quantum.Cron.attach_telemetry_handler()
end
end

defp resolve_in_app_module_allow_list do
Enum.flat_map(Config.in_app_otp_apps(), fn app ->
case :application.get_key(app, :modules) do
{:ok, modules} -> modules
_ -> []
end
end)
end
end
17 changes: 17 additions & 0 deletions lib/sentry/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,20 @@ defmodule Sentry.Config do
The number of lines of source code
before and after the line that caused the exception to report.
"""
],
in_app_otp_apps: [
type: {:list, :atom},
default: [],
type_doc: "list of `t:atom/0`",
doc: """
A list of OTP application names that will be used to populate additional modules for the
`:in_app_module_allow_list` option. List your application (or the applications in your
umbrella project) for them to show as "in-app" in stacktraces in Sentry. We recommend using
this option over `:in_app_module_allow_list`, unless you need more control over the exact
modules to consider as "in-app".

*Available since v10.9.0*.
"""
]
]

Expand Down Expand Up @@ -575,6 +589,9 @@ defmodule Sentry.Config do
@spec report_deps?() :: boolean()
def report_deps?, do: fetch!(:report_deps)

@spec in_app_otp_apps() :: [atom()]
def in_app_otp_apps, do: fetch!(:in_app_otp_apps)

@spec json_library() :: module()
def json_library, do: fetch!(:json_library)

Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ defmodule Sentry.Mixfile do

defp run_integration_tests_if_supported(args) do
if Version.match?(System.version(), ">= 1.16.0") do
run_integration_tests("umbrella", args)
run_integration_tests("phoenix_app", args)
else
Mix.shell().info("Skipping integration tests for Elixir versions < 1.16")
Expand Down
5 changes: 5 additions & 0 deletions test_integrations/umbrella/.formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Used by "mix format"
[
inputs: ["mix.exs", "config/*.exs"],
subdirectories: ["apps/*"]
]
20 changes: 20 additions & 0 deletions test_integrations/umbrella/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Temporary files, for example, from tests.
/tmp/
4 changes: 4 additions & 0 deletions test_integrations/umbrella/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# PhoenixAppUmbrella

**TODO: Add description**

4 changes: 4 additions & 0 deletions test_integrations/umbrella/apps/admin/.formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
23 changes: 23 additions & 0 deletions test_integrations/umbrella/apps/admin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
admin-*.tar

# Temporary files, for example, from tests.
/tmp/
21 changes: 21 additions & 0 deletions test_integrations/umbrella/apps/admin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Admin

**TODO: Add description**

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `admin` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:admin, "~> 0.1.0"}
]
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at <https://hexdocs.pm/admin>.

18 changes: 18 additions & 0 deletions test_integrations/umbrella/apps/admin/lib/admin.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule Admin do
@moduledoc """
Documentation for `Admin`.
"""

@doc """
Hello world.

## Examples

iex> Admin.hello()
:world

"""
def hello do
:world
end
end
3 changes: 3 additions & 0 deletions test_integrations/umbrella/apps/admin/lib/admin/settings.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule Admin.Settings do
defstruct [:key, :value]
end
33 changes: 33 additions & 0 deletions test_integrations/umbrella/apps/admin/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
defmodule Admin.MixProject do
use Mix.Project

def project do
[
app: :admin,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.18",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"},
# {:sibling_app_in_umbrella, in_umbrella: true}
]
end
end
8 changes: 8 additions & 0 deletions test_integrations/umbrella/apps/admin/test/admin_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule Admin.Sentry.ConfigTest do
use ExUnit.Case

test "loads in_app_module_allow_list" do
assert Sentry.Config.in_app_module_allow_list() |> Enum.sort() ==
[Admin, Admin.Settings, Public, Public.User]
end
end
5 changes: 5 additions & 0 deletions test_integrations/umbrella/apps/admin/test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Application.start(:nimble_options)
Application.start(:nimble_ownership)
Application.start(:sentry)

ExUnit.start()
4 changes: 4 additions & 0 deletions test_integrations/umbrella/apps/public/.formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
23 changes: 23 additions & 0 deletions test_integrations/umbrella/apps/public/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
public-*.tar

# Temporary files, for example, from tests.
/tmp/
21 changes: 21 additions & 0 deletions test_integrations/umbrella/apps/public/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Public

**TODO: Add description**

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `public` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:public, "~> 0.1.0"}
]
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at <https://hexdocs.pm/public>.

18 changes: 18 additions & 0 deletions test_integrations/umbrella/apps/public/lib/public.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule Public do
@moduledoc """
Documentation for `Public`.
"""

@doc """
Hello world.

## Examples

iex> Public.hello()
:world

"""
def hello do
:world
end
end
3 changes: 3 additions & 0 deletions test_integrations/umbrella/apps/public/lib/public/user.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule Public.User do
defstruct [:id, :name]
end
33 changes: 33 additions & 0 deletions test_integrations/umbrella/apps/public/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
defmodule Public.MixProject do
use Mix.Project

def project do
[
app: :public,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.18",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"},
# {:sibling_app_in_umbrella, in_umbrella: true}
]
end
end
8 changes: 8 additions & 0 deletions test_integrations/umbrella/apps/public/test/public_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule Public.Sentry.ConfigTest do
use ExUnit.Case

test "loads in_app_module_allow_list" do
assert Sentry.Config.in_app_module_allow_list() |> Enum.sort() ==
[Admin, Admin.Settings, Public, Public.User]
end
end
5 changes: 5 additions & 0 deletions test_integrations/umbrella/apps/public/test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Application.start(:nimble_options)
Application.start(:nimble_ownership)
Application.start(:sentry)

ExUnit.start()
27 changes: 27 additions & 0 deletions test_integrations/umbrella/config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This file is responsible for configuring your umbrella
# and **all applications** and their dependencies with the
# help of the Config module.
#
# Note that all applications in your umbrella share the
# same configuration and dependencies, which is why they
# all use the same configuration file. If you want different
# configurations or dependencies per app, it is best to
# move said applications out of the umbrella.
import Config

# Sample configuration:
#
# config :logger, :console,
# level: :info,
# format: "$date $time [$level] $metadata$message\n",
# metadata: [:user_id]
#

config :sentry,
dsn: "http://public:secret@localhost:8080/1",
environment_name: Mix.env(),
enable_source_code_context: true,
root_source_code_paths: [File.cwd!()],
test_mode: true,
send_result: :sync,
in_app_otp_apps: [:public, :admin]
25 changes: 25 additions & 0 deletions test_integrations/umbrella/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
defmodule Umbrella.MixProject do
use Mix.Project

def project do
[
apps_path: "apps",
version: "0.1.0",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end

# Dependencies listed here are available only for this
# project and cannot be accessed from applications inside
# the apps folder.
#
# Run "mix help deps" for examples and options.
defp deps do
[
{:hackney, "~> 1.18"},
{:jason, "~> 1.4"},
{:sentry, path: "../.."}
]
end
end
Loading
Loading