Skip to content

Commit acdb601

Browse files
committed
send modules
1 parent c50e9a4 commit acdb601

File tree

6 files changed

+39
-2
lines changed

6 files changed

+39
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ config :sentry,
7575
| `after_send_event` | False | | |
7676
| `sample_rate` | False | 1.0 | |
7777
| `in_app_module_whitelist` | False | `[]` | |
78+
| `report_deps` | False | True | Will attempt to load Mix dependencies at compile time to report alongside events |
7879
| `enable_source_code_context` | True | | |
7980
| `root_source_code_path` | Required if `enable_source_code_context` is enabled | | Should generally be set to `File.cwd!`|
8081
| `context_lines` | False | 3 | |

docs/config.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ Optional settings
9797

9898
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 ``[]``.
9999

100+
.. describe:: report_deps
101+
102+
Will attempt to load Mix dependencies at runtime to report alongside events. Defaults to `true`.
103+
100104
.. describe:: context_lines
101105

102106
The number of lines of source code before and after the line that caused the exception to be included. Defaults to ``3``.

lib/sentry/config.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ defmodule Sentry.Config do
101101
get_config(:after_send_event, check_dsn: false)
102102
end
103103

104+
def report_deps do
105+
get_config(:report_deps, default: true, check_dsn: false)
106+
end
107+
104108
defp get_config(key, opts \\ []) when is_atom(key) do
105109
default = Keyword.get(opts, :default)
106110
check_dsn = Keyword.get(opts, :check_dsn, true)

lib/sentry/event.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ defmodule Sentry.Event do
77
### Configuration
88
99
* `: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 `[]`.
10+
* `:report_deps` - Flag for whether to include the loaded dependencies when reporting an error. Defaults to true.
1011
1112
"""
1213

@@ -28,14 +29,18 @@ defmodule Sentry.Event do
2829
extra: %{},
2930
user: %{},
3031
breadcrumbs: [],
31-
fingerprint: []
32+
fingerprint: [],
33+
modules: %{}
3234

3335
@type t :: %__MODULE__{}
3436

3537
alias Sentry.{Event, Util, Config}
3638
@source_code_context_enabled Application.fetch_env!(:sentry, :enable_source_code_context)
3739
@source_files if(@source_code_context_enabled, do: Sentry.Sources.load_files(), else: nil)
3840

41+
@enable_deps_reporting Config.report_deps()
42+
@deps if(@enable_deps_reporting, do: Util.mix_deps_to_map(Mix.Dep.loaded([env: Mix.env])), else: %{})
43+
3944
@doc """
4045
Creates an Event struct out of context collected and options
4146
## Options
@@ -102,7 +107,8 @@ defmodule Sentry.Event do
102107
user: user,
103108
breadcrumbs: breadcrumbs,
104109
request: request,
105-
fingerprint: fingerprint
110+
fingerprint: fingerprint,
111+
modules: @deps,
106112
}
107113
|> add_metadata()
108114
end

lib/sentry/util.ex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,15 @@ defmodule Sentry.Util do
2121
|> DateTime.to_iso8601()
2222
|> String.trim_trailing("Z")
2323
end
24+
25+
def mix_deps_to_map([%Mix.Dep{} | _rest] = modules) do
26+
Enum.reduce(modules, %{}, fn(x, acc) ->
27+
case x.status do
28+
{:ok, version} -> Map.put(acc, x.app, version)
29+
_ -> acc
30+
end
31+
end)
32+
end
33+
34+
def mix_deps_to_map(modules), do: modules
2435
end

test/event_test.exs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,15 @@ defmodule Sentry.EventTest do
124124
},
125125
]} == event.stacktrace
126126
end
127+
128+
test "transforms mix deps to map of modules" do
129+
exception = RuntimeError.exception("error")
130+
event = Sentry.Event.transform_exception(exception, [])
131+
132+
assert event.modules == %{bunt: "0.2.0", bypass: "0.7.0", certifi: "1.1.0", cowboy: "1.1.2",
133+
cowlib: "1.0.2", credo: "0.8.1", hackney: "1.8.0", idna: "4.0.0",
134+
metrics: "1.0.1", mime: "1.1.0", mimerl: "1.0.2", plug: "1.3.5",
135+
poison: "3.1.0", ranch: "1.3.2", ssl_verify_fun: "1.1.1",
136+
uuid: "1.1.7"}
137+
end
127138
end

0 commit comments

Comments
 (0)