This commit is contained in:
parent
6e635d1b30
commit
df44be2b1b
@ -4,7 +4,7 @@ defmodule Memex.Application do
|
|||||||
@moduledoc false
|
@moduledoc false
|
||||||
|
|
||||||
use Application
|
use Application
|
||||||
alias Memex.ErrorReporter
|
alias Memex.Logger
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def start(_type, _args) do
|
def start(_type, _args) do
|
||||||
@ -33,7 +33,7 @@ defmodule Memex.Application do
|
|||||||
[:oban, :job, :start],
|
[:oban, :job, :start],
|
||||||
[:oban, :job, :stop]
|
[:oban, :job, :stop]
|
||||||
],
|
],
|
||||||
&ErrorReporter.handle_event/4,
|
&Logger.handle_event/4,
|
||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
defmodule Memex.ErrorReporter do
|
defmodule Memex.Logger do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Custom logger for telemetry events
|
Custom logger for telemetry events
|
||||||
|
|
||||||
@ -12,41 +12,47 @@ defmodule Memex.ErrorReporter do
|
|||||||
data =
|
data =
|
||||||
get_oban_job_data(meta, measure)
|
get_oban_job_data(meta, measure)
|
||||||
|> Map.put(:stacktrace, Exception.format_stacktrace(stacktrace))
|
|> Map.put(:stacktrace, Exception.format_stacktrace(stacktrace))
|
||||||
|
|> pretty_encode()
|
||||||
|
|
||||||
Logger.error(meta.reason, data: pretty_encode(data))
|
Logger.error(meta.reason, data: data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_event([:oban, :job, :start], measure, meta, _config) do
|
def handle_event([:oban, :job, :start], measure, meta, _config) do
|
||||||
Logger.info("Started oban job", data: get_oban_job_data(meta, measure) |> pretty_encode())
|
data = get_oban_job_data(meta, measure) |> pretty_encode()
|
||||||
|
Logger.info("Started oban job", data: data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_event([:oban, :job, :stop], measure, meta, _config) do
|
def handle_event([:oban, :job, :stop], measure, meta, _config) do
|
||||||
Logger.info("Finished oban job", data: get_oban_job_data(meta, measure) |> pretty_encode())
|
data = get_oban_job_data(meta, measure) |> pretty_encode()
|
||||||
|
Logger.info("Finished oban job", data: data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_event([:oban, :job, unhandled_event], measure, meta, _config) do
|
def handle_event([:oban, :job, unhandled_event], measure, meta, _config) do
|
||||||
data =
|
data =
|
||||||
get_oban_job_data(meta, measure)
|
get_oban_job_data(meta, measure)
|
||||||
|> Map.put(:event, unhandled_event)
|
|> Map.put(:event, unhandled_event)
|
||||||
|
|> pretty_encode()
|
||||||
|
|
||||||
Logger.warning("Unhandled oban job event", data: pretty_encode(data))
|
Logger.warning("Unhandled oban job event", data: data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_event(unhandled_event, measure, meta, config) do
|
def handle_event(unhandled_event, measure, meta, config) do
|
||||||
data = %{
|
data =
|
||||||
event: unhandled_event,
|
pretty_encode(%{
|
||||||
meta: meta,
|
event: unhandled_event,
|
||||||
measurements: measure,
|
meta: meta,
|
||||||
config: config
|
measurements: measure,
|
||||||
}
|
config: config
|
||||||
|
})
|
||||||
|
|
||||||
Logger.warning("Unhandled telemetry event", data: pretty_encode(data))
|
Logger.warning("Unhandled telemetry event", data: data)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_oban_job_data(%{job: job}, measure) do
|
defp get_oban_job_data(%{job: job}, measure) do
|
||||||
job
|
%{
|
||||||
|> Map.take([:id, :args, :meta, :queue, :worker])
|
job: job |> Map.take([:id, :args, :meta, :queue, :worker]),
|
||||||
|> Map.merge(measure)
|
measurements: measure
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp pretty_encode(data) do
|
defp pretty_encode(data) do
|
Loading…
Reference in New Issue
Block a user