Skip to content

Commit e0503b2

Browse files
Merge pull request #185 from getsentry/fix-logger-and-context-usage
Fix logger and context usage
2 parents aaf6f4a + 4e621a2 commit e0503b2

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/sentry/logger.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ defmodule Sentry.Logger do
2626
{kind, exception, stacktrace, module} = get_exception_and_stacktrace(message[:error_info])
2727
|> get_initial_call_and_module(message)
2828

29-
opts = get_in(message, ~w[dictionary sentry_context]a) || %{}
29+
opts = (get_in(message, ~w[dictionary sentry_context]a) || %{})
3030
|> Map.take(Sentry.Context.context_keys)
3131
|> Map.to_list()
3232
|> Keyword.put(:event_source, :logger)

test/logger_test.exs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,32 @@ defmodule Sentry.LoggerTest do
110110
end
111111
:error_logger.delete_report_handler(Sentry.Logger)
112112
end
113+
114+
test "error_logger passes context properly" do
115+
bypass = Bypass.open
116+
pid = self()
117+
Bypass.expect bypass, fn conn ->
118+
{:ok, body, conn} = Plug.Conn.read_body(conn)
119+
body = Poison.decode!(body)
120+
assert get_in(body, ["extra", "fruit"]) == "apples"
121+
assert conn.request_path == "/api/1/store/"
122+
assert conn.method == "POST"
123+
send(pid, "API called")
124+
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
125+
end
126+
127+
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
128+
:error_logger.add_report_handler(Sentry.Logger)
129+
130+
capture_log fn ->
131+
Task.start( fn ->
132+
Sentry.Context.set_extra_context(%{fruit: "apples"})
133+
raise "Unique Error"
134+
end)
135+
136+
assert_receive "API called"
137+
end
138+
139+
:error_logger.delete_report_handler(Sentry.Logger)
140+
end
113141
end

0 commit comments

Comments
 (0)