Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oban : logs des composants importants #4410

Merged
merged 2 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions apps/transport/lib/jobs/oban_logger.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
defmodule Transport.Jobs.ObanLogger do
@moduledoc """
Logs the Oban job exceptions as warnings
Setup telemetry/logging for Oban.

We:
- log job exceptions as warnings
- log Oban events related to the orchestration (notifier, queues, plugins etc.)
- we send an email when a job failed after its maximum attempt for jobs with a specific tag
"""
require Logger

@tag_email_on_failure "email_on_failure"

@doc """
Expand Down Expand Up @@ -35,5 +41,22 @@ defmodule Transport.Jobs.ObanLogger do
)
end

def setup, do: :telemetry.attach("oban-logger", [:oban, :job, :exception], &handle_event/4, nil)
def setup do
:telemetry.attach("oban-logger", [:oban, :job, :exception], &handle_event/4, nil)

# Log recommended events for production.
# We leave out `job` events because job start/end can be quite noisy.
# https://hexdocs.pm/oban/preparing_for_production.html#logging
# https://hexdocs.pm/oban/Oban.Telemetry.html
# We may simplify this when
# https://github.com/oban-bg/oban/commit/13eabe3f8019e350ef979369a26f186bdf7be63e
# will be released.
events = [
[:oban, :notifier, :switch],
[:oban, :queue, :shutdown],
[:oban, :stager, :switch]
]

:telemetry.attach_many("oban-default-logger", events, &Oban.Telemetry.handle_event/4, encode: true, level: :info)
end
end
13 changes: 13 additions & 0 deletions apps/transport/test/transport/jobs/oban_logger_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,17 @@ defmodule Transport.Test.Transport.Jobs.ObanLoggerTest do
"Un job Oban Transport.Test.Transport.Jobs.ObanLoggerJobTag vient d'échouer, il serait bien d'investiguer."
)
end

test "oban default logger is set up for important components" do
registered_handlers = Enum.filter(:telemetry.list_handlers([]), &(&1.id == "oban-default-logger"))

assert Enum.count(registered_handlers) > 0

components =
registered_handlers
|> Enum.map(fn %{event_name: [:oban, component, _]} -> component end)
|> MapSet.new()

assert MapSet.new([:notifier, :queue, :stager]) == MapSet.new(components)
end
end
Loading