Skip to content

Commit

Permalink
split log_event from other user metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Aug 2, 2024
1 parent 7dafcee commit 5bee757
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions lib/tower/event.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
defmodule Tower.Event do
defstruct [:id, :time, :level, :kind, :reason, :stacktrace, :metadata]
defstruct [:id, :time, :level, :kind, :reason, :stacktrace, :log_event, :metadata]

@type metadata :: %{optional(:log_event) => :logger.log_event()}
@type error_kind :: :error | :exit | :throw
@type non_error_kind :: :message
@type reason :: Exception.t() | term()
Expand All @@ -13,7 +12,8 @@ defmodule Tower.Event do
kind: error_kind() | non_error_kind(),
reason: reason(),
stacktrace: Exception.stacktrace() | nil,
metadata: metadata()
log_event: :logger.log_event() | nil,
metadata: map()
}

@spec from_caught(Exception.kind(), reason(), Exception.stacktrace()) :: t()
Expand Down Expand Up @@ -49,9 +49,8 @@ defmodule Tower.Event do
kind: :error,
reason: exception,
stacktrace: stacktrace,
metadata:
%{log_event: log_event}
|> Map.merge(Keyword.get(options, :metadata, %{}))
log_event: log_event,
metadata: Keyword.get(options, :metadata, %{})
}
end

Expand All @@ -67,9 +66,8 @@ defmodule Tower.Event do
kind: :exit,
reason: reason,
stacktrace: stacktrace,
metadata:
%{log_event: log_event}
|> Map.merge(Keyword.get(options, :metadata, %{}))
log_event: log_event,
metadata: Keyword.get(options, :metadata, %{})
}
end

Expand All @@ -85,9 +83,8 @@ defmodule Tower.Event do
kind: :throw,
reason: reason,
stacktrace: stacktrace,
metadata:
%{log_event: log_event}
|> Map.merge(Keyword.get(options, :metadata, %{}))
log_event: log_event,
metadata: Keyword.get(options, :metadata, %{})
}
end

Expand All @@ -102,9 +99,8 @@ defmodule Tower.Event do
level: level,
kind: :message,
reason: message,
metadata:
%{log_event: log_event}
|> Map.merge(Keyword.get(options, :metadata, %{}))
log_event: log_event,
metadata: Keyword.get(options, :metadata, %{})
}
end

Expand Down

0 comments on commit 5bee757

Please sign in to comment.