Skip to content

Commit d078240

Browse files
committed
add test for log_level
1 parent ace9faf commit d078240

File tree

2 files changed

+60
-8
lines changed

2 files changed

+60
-8
lines changed

test/client_test.exs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,49 @@ defmodule Sentry.ClientTest do
274274
:unsampled = Sentry.capture_exception(e, result: :sync, sample_rate: 0.0)
275275
end
276276
end
277+
278+
test "logs errors at configured log_level" do
279+
bypass = Bypass.open()
280+
pid = self()
281+
282+
Bypass.expect(bypass, fn conn ->
283+
{:ok, _body, conn} = Plug.Conn.read_body(conn)
284+
assert conn.request_path == "/api/1/store/"
285+
assert conn.method == "POST"
286+
287+
conn =
288+
conn
289+
|> Plug.Conn.put_resp_header(
290+
"X-Sentry-Error",
291+
"Creation of this event was denied due to various reasons."
292+
)
293+
|> Plug.Conn.resp(400, "Something bad happened")
294+
295+
send(pid, "API called")
296+
conn
297+
end)
298+
299+
modify_env(
300+
:sentry,
301+
dsn: "http://public:secret@localhost:#{bypass.port}/1",
302+
client: Sentry.Client,
303+
log_level: :error
304+
)
305+
306+
capture_log(fn ->
307+
try do
308+
Event.not_a_function()
309+
rescue
310+
e ->
311+
{:ok, task} =
312+
Sentry.capture_exception(
313+
e,
314+
stacktrace: __STACKTRACE__
315+
)
316+
317+
assert_receive "API called"
318+
Task.shutdown(task)
319+
end
320+
end) =~ "[error] Failed to send Sentry event"
321+
end
277322
end

test/support/test_client.exs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,26 @@ defmodule Sentry.TestClient do
1515
{:ok, id}
1616

1717
{:error, error} ->
18-
Logger.warn(fn ->
19-
[
20-
"Failed to send Sentry event.",
21-
?\n,
22-
"Event ID: #{event.event_id} - #{inspect(error)} - #{body}"
23-
]
24-
end)
18+
Logger.log(
19+
Sentry.Config.log_level(),
20+
fn ->
21+
[
22+
"Failed to send Sentry event.",
23+
?\n,
24+
"Event ID: #{event.event_id} - #{inspect(error)} - #{body}"
25+
]
26+
end
27+
)
2528

2629
:error
2730
end
2831

2932
{:error, error} ->
30-
Logger.error("Error sending in Sentry.TestClient: #{inspect(error)}")
33+
Logger.log(
34+
Sentry.Config.log_level(),
35+
"Error sending in Sentry.TestClient: #{inspect(error)}"
36+
)
37+
3138
:error
3239
end
3340
end

0 commit comments

Comments
 (0)