forked from getsentry/sentry-elixir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent_test.exs
145 lines (134 loc) · 5.83 KB
/
event_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
defmodule Sentry.EventTest do
use ExUnit.Case, async: true
alias Sentry.Event
import Sentry.TestEnvironmentHelper
def event_generated_by_exception(extra \\ %{}) do
try do
Event.not_a_function(1, 2, 3)
rescue
e -> Event.transform_exception(e, [stacktrace: System.stacktrace, extra: extra])
end
end
test "parses error exception" do
event = event_generated_by_exception()
assert event.platform == "elixir"
assert event.culprit == "Sentry.Event.not_a_function/3"
assert event.extra == %{}
assert event.exception == [
%{type: UndefinedFunctionError,
value: "function Sentry.Event.not_a_function/3 is undefined or private",
module: nil}
]
assert event.level == "error"
assert event.message == "(UndefinedFunctionError) function Sentry.Event.not_a_function/3 is undefined or private"
assert is_binary(event.server_name)
assert event.stacktrace == %{
frames: Enum.reverse([
%{filename: nil, function: "Sentry.Event.not_a_function/3", lineno: nil, module: Sentry.Event, context_line: nil, post_context: [], pre_context: [], in_app: false, vars: %{"arg0" => "1", "arg1" => "2", "arg2" => "3"}},
%{filename: "test/event_test.exs", function: "Sentry.EventTest.event_generated_by_exception/1", lineno: 8, module: Sentry.EventTest, context_line: nil, post_context: [], pre_context: [], in_app: false, vars: %{}},
%{filename: "test/event_test.exs", function: "Sentry.EventTest.\"test parses error exception\"/1", lineno: 15, module: Sentry.EventTest, context_line: nil, post_context: [], pre_context: [], in_app: false, vars: %{}},
%{filename: "lib/ex_unit/runner.ex", function: "ExUnit.Runner.exec_test/1", lineno: 302, module: ExUnit.Runner, context_line: nil, post_context: [], pre_context: [], in_app: false, vars: %{}},
%{filename: "timer.erl", function: ":timer.tc/1", lineno: 166, module: :timer, context_line: nil, post_context: [], pre_context: [], in_app: false, vars: %{}},
%{filename: "lib/ex_unit/runner.ex", function: "anonymous fn/3 in ExUnit.Runner.spawn_test/3", lineno: 250, module: ExUnit.Runner, context_line: nil, post_context: [], pre_context: [], in_app: false, vars: %{}}])
}
assert event.tags == %{}
assert event.timestamp =~ ~r/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/
end
test "respects tags in config" do
modify_env(:sentry, tags: %{testing: "tags"})
event = event_generated_by_exception()
assert event.tags == %{testing: "tags"}
end
test "respects extra information passed in" do
event = event_generated_by_exception(%{extra_data: "data"})
assert event.extra == %{extra_data: "data"}
end
test "create_event works for message" do
%Sentry.Event{
breadcrumbs: [],
culprit: nil,
environment: :test,
exception: nil,
extra: %{},
level: "error",
message: "Test message",
platform: "elixir",
release: nil,
request: %{},
stacktrace: %{frames: []},
tags: %{},
user: %{}} = Event.create_event(message: "Test message")
end
test "only sending fingerprint when set" do
exception = RuntimeError.exception("error")
event = Sentry.Event.transform_exception(exception, [fingerprint: ["hello", "world"]])
assert event.fingerprint == ["hello", "world"]
end
test "not sending fingerprint when unset" do
exception = RuntimeError.exception("error")
event = Sentry.Event.transform_exception(exception, [])
assert event.fingerprint == ["{{ default }}"]
end
test "sets app_frame to true when configured" do
modify_env(:sentry, in_app_module_whitelist: [Sentry, :random, Sentry.Submodule])
exception = RuntimeError.exception("error")
event = Sentry.Event.transform_exception(exception, [stacktrace: [{Elixir.Sentry.Fun, :method, 2, []}, {Elixir.Sentry, :other_method, 4, []},
{:other_module, :a_method, 8, []}, {:random, :uniform, 0, []},
{Sentry.Submodule.Fun, :this_method, 0, []}]])
assert %{
frames: [
%{
module: Sentry.Submodule.Fun,
function: "Sentry.Submodule.Fun.this_method/0",
in_app: true,
filename: nil, lineno: nil,
context_line: nil, post_context: [], pre_context: [],
vars: %{},
},
%{
module: :random,
function: ":random.uniform/0",
in_app: true,
filename: nil, lineno: nil,
context_line: nil, post_context: [], pre_context: [],
vars: %{},
},
%{
module: :other_module,
function: ":other_module.a_method/8",
in_app: false,
filename: nil, lineno: nil,
context_line: nil, post_context: [], pre_context: [],
vars: %{},
},
%{
module: Sentry,
function: "Sentry.other_method/4",
in_app: true,
filename: nil, lineno: nil,
context_line: nil, post_context: [], pre_context: [],
vars: %{},
},
%{
filename: nil,
function: "Sentry.Fun.method/2",
module: Sentry.Fun,
lineno: nil,
in_app: true,
context_line: nil,
post_context: [],
pre_context: [],
vars: %{},
},
]} == event.stacktrace
end
test "transforms mix deps to map of modules" do
exception = RuntimeError.exception("error")
event = Sentry.Event.transform_exception(exception, [])
assert event.modules == %{bunt: "0.2.0", bypass: "0.8.1", certifi: "1.1.0", cowboy: "1.1.2",
cowlib: "1.0.2", credo: "0.8.6", hackney: "1.8.0", idna: "4.0.0",
metrics: "1.0.1", mime: "1.1.0", mimerl: "1.0.2", plug: "1.4.3",
poison: "3.1.0", ranch: "1.3.2", ssl_verify_fun: "1.1.1",
uuid: "1.1.7"}
end
end