Skip to content

Commit

Permalink
time
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Jun 4, 2024
1 parent d8fcb08 commit ca66d6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/tower/ephemeral_reporter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ defmodule Tower.EphemeralReporter do
Agent.start_link(fn -> [] end, name: __MODULE__)
end

def report_exception(exception, stacktrace, _meta \\ %{})
def report_exception(exception, stacktrace, meta \\ %{})
when is_exception(exception) and is_list(stacktrace) do
Agent.update(
__MODULE__,
fn errors ->
[
%{
timestamp: DateTime.utc_now(),
time: Map.get(meta, :time, :logger.timestamp()),
type: exception.__struct__,
reason: Exception.message(exception),
stacktrace: stacktrace
Expand All @@ -23,13 +23,18 @@ defmodule Tower.EphemeralReporter do
)
end

def report(type, reason, stacktrace, _meta \\ %{})
def report(type, reason, stacktrace, meta \\ %{})
when is_atom(type) and is_binary(reason) and is_list(stacktrace) do
Agent.update(
__MODULE__,
fn errors ->
[
%{timestamp: DateTime.utc_now(), type: type, reason: reason, stacktrace: stacktrace}
%{
time: Map.get(meta, :time, :logger.timestamp()),
type: type,
reason: reason,
stacktrace: stacktrace
}
| errors
]
end
Expand Down
3 changes: 3 additions & 0 deletions test/tower_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ defmodule TowerTest do
assert(
[
%{
time: _,
type: RuntimeError,
reason: "error inside process",
stacktrace: stacktrace
Expand All @@ -46,6 +47,7 @@ defmodule TowerTest do
assert(
[
%{
time: _,
type: :nocatch,
reason: "error",
stacktrace: stacktrace
Expand All @@ -66,6 +68,7 @@ defmodule TowerTest do
assert(
[
%{
time: _,
type: ArithmeticError,
reason: "bad argument in arithmetic expression",
stacktrace: stacktrace
Expand Down

0 comments on commit ca66d6c

Please sign in to comment.