Skip to content

Commit

Permalink
Include node name in peer telemetry logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sorentwo committed Jan 15, 2025
1 parent c36c7fe commit 01a29a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/oban/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ defmodule Oban.Telemetry do
* `event` — always `peer:election`
* `leader` — boolean indicating whether the peer is the leader
* `message` — information about the peers role in an election
* `node` — the name of the node that changed leadership
* `was_leader` — boolean indicating whether the peer was leader before the election
#### Plugin Events
Expand Down Expand Up @@ -537,8 +538,9 @@ defmodule Oban.Telemetry do
%{
event: "peer:election",
leader: leader,
was_leader: was_leader,
message: message
message: message,
node: meta.conf.node,
was_leader: was_leader
}
end)
end
Expand Down
3 changes: 2 additions & 1 deletion test/oban/telemetry_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,15 @@ defmodule Oban.TelemetryTest do
logged =
capture_log(fn ->
:telemetry.execute([:oban, :peer, :election, :stop], %{}, %{
conf: %{},
conf: %{node: "worker.1"},
leader: true,
was_leader: false
})
end)

assert logged =~ ~s("event":"peer:election")
assert logged =~ ~s("leader":true)
assert logged =~ ~s("node":"worker.1")
assert logged =~ ~s("was_leader":false)
assert logged =~ ~s("message":"peer became leader")
end
Expand Down

0 comments on commit 01a29a7

Please sign in to comment.