Skip to content

Commit fbbf707

Browse files
solnicwhatyouhide
andauthored
Add :in_app_otp_apps option (#854)
Co-authored-by: Andrea Leopardi <[email protected]>
1 parent b72e78a commit fbbf707

25 files changed

+355
-0
lines changed

lib/sentry/application.ex

+14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ defmodule Sentry.Application do
1010
config = Config.validate!()
1111
:ok = Config.persist(config)
1212

13+
Config.put_config(
14+
:in_app_module_allow_list,
15+
Config.in_app_module_allow_list() ++ resolve_in_app_module_allow_list()
16+
)
17+
1318
http_client = Keyword.fetch!(config, :client)
1419

1520
maybe_http_client_spec =
@@ -71,4 +76,13 @@ defmodule Sentry.Application do
7176
Sentry.Integrations.Quantum.Cron.attach_telemetry_handler()
7277
end
7378
end
79+
80+
defp resolve_in_app_module_allow_list do
81+
Enum.flat_map(Config.in_app_otp_apps(), fn app ->
82+
case :application.get_key(app, :modules) do
83+
{:ok, modules} -> modules
84+
_ -> []
85+
end
86+
end)
87+
end
7488
end

lib/sentry/config.ex

+17
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,20 @@ defmodule Sentry.Config do
388388
The number of lines of source code
389389
before and after the line that caused the exception to report.
390390
"""
391+
],
392+
in_app_otp_apps: [
393+
type: {:list, :atom},
394+
default: [],
395+
type_doc: "list of `t:atom/0`",
396+
doc: """
397+
A list of OTP application names that will be used to populate additional modules for the
398+
`:in_app_module_allow_list` option. List your application (or the applications in your
399+
umbrella project) for them to show as "in-app" in stacktraces in Sentry. We recommend using
400+
this option over `:in_app_module_allow_list`, unless you need more control over the exact
401+
modules to consider as "in-app".
402+
403+
*Available since v10.9.0*.
404+
"""
391405
]
392406
]
393407

@@ -575,6 +589,9 @@ defmodule Sentry.Config do
575589
@spec report_deps?() :: boolean()
576590
def report_deps?, do: fetch!(:report_deps)
577591

592+
@spec in_app_otp_apps() :: [atom()]
593+
def in_app_otp_apps, do: fetch!(:in_app_otp_apps)
594+
578595
@spec json_library() :: module()
579596
def json_library, do: fetch!(:json_library)
580597

mix.exs

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ defmodule Sentry.Mixfile do
136136

137137
defp run_integration_tests_if_supported(args) do
138138
if Version.match?(System.version(), ">= 1.16.0") do
139+
run_integration_tests("umbrella", args)
139140
run_integration_tests("phoenix_app", args)
140141
else
141142
Mix.shell().info("Skipping integration tests for Elixir versions < 1.16")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Used by "mix format"
2+
[
3+
inputs: ["mix.exs", "config/*.exs"],
4+
subdirectories: ["apps/*"]
5+
]

test_integrations/umbrella/.gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where third-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# If the VM crashes, it generates a dump, let's ignore it too.
14+
erl_crash.dump
15+
16+
# Also ignore archive artifacts (built via "mix archive.build").
17+
*.ez
18+
19+
# Temporary files, for example, from tests.
20+
/tmp/

test_integrations/umbrella/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# PhoenixAppUmbrella
2+
3+
**TODO: Add description**
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Used by "mix format"
2+
[
3+
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
4+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where third-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# If the VM crashes, it generates a dump, let's ignore it too.
14+
erl_crash.dump
15+
16+
# Also ignore archive artifacts (built via "mix archive.build").
17+
*.ez
18+
19+
# Ignore package tarball (built via "mix hex.build").
20+
admin-*.tar
21+
22+
# Temporary files, for example, from tests.
23+
/tmp/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Admin
2+
3+
**TODO: Add description**
4+
5+
## Installation
6+
7+
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
8+
by adding `admin` to your list of dependencies in `mix.exs`:
9+
10+
```elixir
11+
def deps do
12+
[
13+
{:admin, "~> 0.1.0"}
14+
]
15+
end
16+
```
17+
18+
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
19+
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
20+
be found at <https://hexdocs.pm/admin>.
21+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
defmodule Admin do
2+
@moduledoc """
3+
Documentation for `Admin`.
4+
"""
5+
6+
@doc """
7+
Hello world.
8+
9+
## Examples
10+
11+
iex> Admin.hello()
12+
:world
13+
14+
"""
15+
def hello do
16+
:world
17+
end
18+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
defmodule Admin.Settings do
2+
defstruct [:key, :value]
3+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
defmodule Admin.MixProject do
2+
use Mix.Project
3+
4+
def project do
5+
[
6+
app: :admin,
7+
version: "0.1.0",
8+
build_path: "../../_build",
9+
config_path: "../../config/config.exs",
10+
deps_path: "../../deps",
11+
lockfile: "../../mix.lock",
12+
elixir: "~> 1.18",
13+
start_permanent: Mix.env() == :prod,
14+
deps: deps()
15+
]
16+
end
17+
18+
# Run "mix help compile.app" to learn about applications.
19+
def application do
20+
[
21+
extra_applications: [:logger]
22+
]
23+
end
24+
25+
# Run "mix help deps" to learn about dependencies.
26+
defp deps do
27+
[
28+
# {:dep_from_hexpm, "~> 0.3.0"},
29+
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"},
30+
# {:sibling_app_in_umbrella, in_umbrella: true}
31+
]
32+
end
33+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
defmodule Admin.Sentry.ConfigTest do
2+
use ExUnit.Case
3+
4+
test "loads in_app_module_allow_list" do
5+
assert Sentry.Config.in_app_module_allow_list() |> Enum.sort() ==
6+
[Admin, Admin.Settings, Public, Public.User]
7+
end
8+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Application.start(:nimble_options)
2+
Application.start(:nimble_ownership)
3+
Application.start(:sentry)
4+
5+
ExUnit.start()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Used by "mix format"
2+
[
3+
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
4+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where third-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# If the VM crashes, it generates a dump, let's ignore it too.
14+
erl_crash.dump
15+
16+
# Also ignore archive artifacts (built via "mix archive.build").
17+
*.ez
18+
19+
# Ignore package tarball (built via "mix hex.build").
20+
public-*.tar
21+
22+
# Temporary files, for example, from tests.
23+
/tmp/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Public
2+
3+
**TODO: Add description**
4+
5+
## Installation
6+
7+
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
8+
by adding `public` to your list of dependencies in `mix.exs`:
9+
10+
```elixir
11+
def deps do
12+
[
13+
{:public, "~> 0.1.0"}
14+
]
15+
end
16+
```
17+
18+
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
19+
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
20+
be found at <https://hexdocs.pm/public>.
21+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
defmodule Public do
2+
@moduledoc """
3+
Documentation for `Public`.
4+
"""
5+
6+
@doc """
7+
Hello world.
8+
9+
## Examples
10+
11+
iex> Public.hello()
12+
:world
13+
14+
"""
15+
def hello do
16+
:world
17+
end
18+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
defmodule Public.User do
2+
defstruct [:id, :name]
3+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
defmodule Public.MixProject do
2+
use Mix.Project
3+
4+
def project do
5+
[
6+
app: :public,
7+
version: "0.1.0",
8+
build_path: "../../_build",
9+
config_path: "../../config/config.exs",
10+
deps_path: "../../deps",
11+
lockfile: "../../mix.lock",
12+
elixir: "~> 1.18",
13+
start_permanent: Mix.env() == :prod,
14+
deps: deps()
15+
]
16+
end
17+
18+
# Run "mix help compile.app" to learn about applications.
19+
def application do
20+
[
21+
extra_applications: [:logger]
22+
]
23+
end
24+
25+
# Run "mix help deps" to learn about dependencies.
26+
defp deps do
27+
[
28+
# {:dep_from_hexpm, "~> 0.3.0"},
29+
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"},
30+
# {:sibling_app_in_umbrella, in_umbrella: true}
31+
]
32+
end
33+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
defmodule Public.Sentry.ConfigTest do
2+
use ExUnit.Case
3+
4+
test "loads in_app_module_allow_list" do
5+
assert Sentry.Config.in_app_module_allow_list() |> Enum.sort() ==
6+
[Admin, Admin.Settings, Public, Public.User]
7+
end
8+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Application.start(:nimble_options)
2+
Application.start(:nimble_ownership)
3+
Application.start(:sentry)
4+
5+
ExUnit.start()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This file is responsible for configuring your umbrella
2+
# and **all applications** and their dependencies with the
3+
# help of the Config module.
4+
#
5+
# Note that all applications in your umbrella share the
6+
# same configuration and dependencies, which is why they
7+
# all use the same configuration file. If you want different
8+
# configurations or dependencies per app, it is best to
9+
# move said applications out of the umbrella.
10+
import Config
11+
12+
# Sample configuration:
13+
#
14+
# config :logger, :console,
15+
# level: :info,
16+
# format: "$date $time [$level] $metadata$message\n",
17+
# metadata: [:user_id]
18+
#
19+
20+
config :sentry,
21+
dsn: "http://public:secret@localhost:8080/1",
22+
environment_name: Mix.env(),
23+
enable_source_code_context: true,
24+
root_source_code_paths: [File.cwd!()],
25+
test_mode: true,
26+
send_result: :sync,
27+
in_app_otp_apps: [:public, :admin]

test_integrations/umbrella/mix.exs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
defmodule Umbrella.MixProject do
2+
use Mix.Project
3+
4+
def project do
5+
[
6+
apps_path: "apps",
7+
version: "0.1.0",
8+
start_permanent: Mix.env() == :prod,
9+
deps: deps()
10+
]
11+
end
12+
13+
# Dependencies listed here are available only for this
14+
# project and cannot be accessed from applications inside
15+
# the apps folder.
16+
#
17+
# Run "mix help deps" for examples and options.
18+
defp deps do
19+
[
20+
{:hackney, "~> 1.18"},
21+
{:jason, "~> 1.4"},
22+
{:sentry, path: "../.."}
23+
]
24+
end
25+
end

0 commit comments

Comments
 (0)