Skip to content

Commit

Permalink
Add debug logging for server side event handling (#15245)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakekaplan authored Sep 6, 2024
1 parent c9fb300 commit a571cf6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/prefect/server/events/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ async def publish_event(self, event: ReceivedEvent):
},
)
return

logger.debug(
"Publishing event: %s with id: %s for resource: %s",
event.event,
event.id,
event.resource.get("prefect.resource.id"),
)
await self.publish_data(
encoded,
{
Expand Down
8 changes: 8 additions & 0 deletions src/prefect/server/events/services/event_persister.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ async def message_handler(message: Message):
return

event = ReceivedEvent.model_validate_json(message.data)

logger.debug(
"Received event: %s with id: %s for resource: %s",
event.event,
event.id,
event.resource.get("prefect.resource.id"),
)

await queue.put(event)

if queue.qsize() >= batch_size:
Expand Down
9 changes: 6 additions & 3 deletions src/prefect/server/services/task_run_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async def record_task_run_event(event: ReceivedEvent):
session, task_run, denormalized_state_attributes
)

logger.info(
logger.debug(
"Recorded task run state change",
extra={
"task_run_id": task_run.id,
Expand All @@ -175,8 +175,11 @@ async def message_handler(message: Message):
if not event.resource.get("prefect.orchestration") == "client":
return

logger.info(
f"Received event: {event.event} with id: {event.id} for resource: {event.resource.get('prefect.resource.id')}"
logger.debug(
"Received event: %s with id: %s for resource: %s",
event.event,
event.id,
event.resource.get("prefect.resource.id"),
)

try:
Expand Down
4 changes: 2 additions & 2 deletions tests/server/services/test_task_run_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ async def test_handle_client_orchestrated_task_run_event(
client_orchestrated_task_run_event: ReceivedEvent,
caplog: pytest.LogCaptureFixture,
):
with caplog.at_level("INFO"):
with caplog.at_level("DEBUG"):
await task_run_recorder_handler(message(client_orchestrated_task_run_event))

assert "Recorded task run state change" in caplog.text
Expand All @@ -175,7 +175,7 @@ async def test_skip_non_task_run_event(
hello_event: ReceivedEvent,
caplog: pytest.LogCaptureFixture,
):
with caplog.at_level("INFO"):
with caplog.at_level("DEBUG"):
await task_run_recorder_handler(message(hello_event))

assert "Received event" not in caplog.text
Expand Down

0 comments on commit a571cf6

Please sign in to comment.