Skip to content

Conversation

@sampaiodiego
Copy link
Member

@sampaiodiego sampaiodiego commented Oct 16, 2025

correctly show error logs

Summary by CodeRabbit

  • Refactor
    • Improved error logging and diagnostics across federation services by implementing standardized structured logging format for better system observability and troubleshooting.
    • Consolidated and optimized error reporting to eliminate redundant debug logs while preserving critical error context.
    • Enhanced error tracking with consistent structured error information across all federation services.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 16, 2025

Walkthrough

This PR systematically refactors error logging across 10 federation-sdk service files, converting string-based and flat error messages to structured object payloads containing msg and err (or other contextual fields), while maintaining identical error handling behavior and control flow.

Changes

Cohort / File(s) Summary
Error Logging Refactoring (msg + err pattern)
packages/federation-sdk/src/services/config.service.ts, database-connection.service.ts, edu.service.ts, event.service.ts, federation-request.service.ts, missing-event.service.ts
Replaced string-based or flat error logging with structured objects containing msg and err fields in catch blocks; control flow and error handling behavior unchanged
Event Authorization Service
packages/federation-sdk/src/services/event-authorization.service.ts
Modified three catch blocks to log structured objects instead of flat parameters; verifyRequestSignature, canAccessEventFromAuthorizationHeader, and canAccessMediaFromAuthorizationHeader now include contextual fields alongside msg and err
State Service
packages/federation-sdk/src/services/state.service.ts
Consolidated separate log parameters into single structured objects with msg, err, and contextual fields (eventId, authEvents) in save state and getServersInRoom error paths
Room Service
packages/federation-sdk/src/services/room.service.ts
Replaced logContext-based logging with inline structured object calls throughout _fetchFullBranch, consistently passing roomId, branchEventId, missing, and status messages
Event Fetcher Service
packages/federation-sdk/src/services/event-fetcher.service.ts
Removed additional debug log lines in federation error path; now logs only error message without per-request details (eventIds, targetServerName)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

The changes follow a consistent refactoring pattern across multiple files (logging format standardization), but vary in structure and context fields per service. Verification requires checking each file for correctness despite the repetitive nature.

Possibly related PRs

  • chore: improve logs #250: Modifies the same federation-sdk service files (event-fetcher.service.ts, room.service.ts) to refactor logging calls from strings to structured object payloads.
  • chore: fix logger usage and dependencies #215: Updates logging usage across federation-sdk service files (config.service.ts, event.service.ts, state.service.ts) with structured-object payload refactoring.
  • feat: partial states (basic) #267: Touches the same service files (event-fetcher.service.ts, room.service.ts, state.service.ts) with method visibility and partial-state logic changes that could conflict with this refactor.

Suggested reviewers

  • rodrigok

Poem

🐰 Logs now dressed in objects fine,
Structured data, line by line,
Error messages dressed with care,
Context everywhere!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "chore: improve error logs" is directly and fully related to the changeset. The raw summary shows that all changes across multiple services (ConfigService, DatabaseConnectionService, EduService, EventAuthorizationService, EventFetcherService, EventService, FederationRequestService, MissingEventService, RoomService, and StateService) consistently involve restructuring error logging from various formats (string-based messages, multiple parameters, interpolated strings) to structured object logging with consistent msg and err fields. The title accurately captures this primary theme and is concise, clear, and specific enough for teammates scanning history to understand that this PR systematically improves error logging consistency and structure across the codebase.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore-improve-error-logs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 23.52941% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.49%. Comparing base (48fccb3) to head (863ecd9).

Files with missing lines Patch % Lines
...kages/federation-sdk/src/services/state.service.ts 0.00% 10 Missing ⚠️
...on-sdk/src/services/database-connection.service.ts 0.00% 2 Missing ⚠️
...ages/federation-sdk/src/services/config.service.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #285      +/-   ##
==========================================
+ Coverage   60.47%   60.49%   +0.02%     
==========================================
  Files          67       67              
  Lines        6676     6675       -1     
==========================================
+ Hits         4037     4038       +1     
+ Misses       2639     2637       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
packages/federation-sdk/src/services/state.service.ts (1)

473-477: Consider adding the err field.

The structured logging at lines 473-477 includes eventId, authEvents, and msg, but is missing the err field. For consistency with other error logs in this PR and to preserve the error details, consider adding err: error to the log object.

Apply this diff:

 			this.logger.error({
 				eventId: event.eventId,
 				authEvents: event.getAuthEventIds(),
 				msg: 'event failed auth check while saving state, this should not have happened while walking an auth chain, the chain is incorrect',
+				err: error,
 			});
packages/federation-sdk/src/services/room.service.ts (3)

1046-1053: Add error message when throwing.

The structured logging looks good, but the thrown error at line 1053 lacks a message, making debugging more difficult.

Apply this diff to add a descriptive error message:

 		this.logger.warn({
 			msg: 'not enough servers participating in the room to retry missing events',
 			roomId,
 			branchEventId: context.event.eventId,
 			missing,
 		});
 
-		throw new Error();
+		throw new Error('Not enough servers participating in the room to retry missing events');

1059-1065: Consider using info level instead of warn.

This logs a retry attempt, which is normal operation rather than a warning condition. The warn level might trigger alerts unnecessarily.

Apply this diff to use a more appropriate log level:

-		this.logger.warn({
+		this.logger.info({
 			msg: 'attempting to fetch events from participating server',
 			askingServer,
 			roomId,
 			branchEventId: context.event.eventId,
 			missing,
 		});

1079-1086: Add error message when throwing.

The structured logging is excellent, but the thrown error at line 1086 lacks a message. This makes it harder to identify the root cause when caught upstream.

Apply this diff to add a descriptive error message:

 		this.logger.error({
 			msg: 'server list exhausted, we still have missing events',
 			roomId,
 			branchEventId: context.event.eventId,
 			missing,
 		});
 
-		throw new Error();
+		throw new Error('Server list exhausted with missing events');
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 48fccb3 and 863ecd9.

📒 Files selected for processing (10)
  • packages/federation-sdk/src/services/config.service.ts (1 hunks)
  • packages/federation-sdk/src/services/database-connection.service.ts (2 hunks)
  • packages/federation-sdk/src/services/edu.service.ts (2 hunks)
  • packages/federation-sdk/src/services/event-authorization.service.ts (3 hunks)
  • packages/federation-sdk/src/services/event-fetcher.service.ts (0 hunks)
  • packages/federation-sdk/src/services/event.service.ts (1 hunks)
  • packages/federation-sdk/src/services/federation-request.service.ts (1 hunks)
  • packages/federation-sdk/src/services/missing-event.service.ts (1 hunks)
  • packages/federation-sdk/src/services/room.service.ts (2 hunks)
  • packages/federation-sdk/src/services/state.service.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • packages/federation-sdk/src/services/event-fetcher.service.ts
🔇 Additional comments (11)
packages/federation-sdk/src/services/federation-request.service.ts (1)

116-119: LGTM!

The conversion to structured error logging is correct. The msg and err fields provide clear context, and the error-rethrowing behavior is preserved.

packages/federation-sdk/src/services/missing-event.service.ts (1)

58-62: LGTM!

The structured logging with additional eventId context is helpful for debugging. The return behavior is preserved correctly.

packages/federation-sdk/src/services/config.service.ts (1)

92-95: LGTM!

Standardizing the error field name from details to err maintains consistency across the codebase. The error handling behavior is preserved.

packages/federation-sdk/src/services/edu.service.ts (1)

46-49: LGTM!

Both catch blocks correctly implement structured error logging with msg and err fields. The error-rethrowing behavior is preserved in both methods.

Also applies to: 85-88

packages/federation-sdk/src/services/event.service.ts (1)

297-301: LGTM!

The structured logging with the edu object provides valuable debugging context. The loop continuation behavior (processing remaining EDUs after an error) is correctly preserved.

packages/federation-sdk/src/services/database-connection.service.ts (1)

15-15: LGTM!

Both database connection error logs correctly use structured logging with msg and err fields. The error handling behavior is preserved in both locations.

Also applies to: 56-56

packages/federation-sdk/src/services/state.service.ts (1)

791-795: LGTM!

The structured logging correctly includes err, eventId, and msg fields. The error-throwing behavior is preserved.

packages/federation-sdk/src/services/event-authorization.service.ts (3)

177-180: LGTM!

The structured error logging with msg and err fields is correct, and the return behavior is preserved.


429-437: LGTM!

The comprehensive structured logging includes all relevant context fields (err, eventId, authorizationHeader, method, uri, body, msg), which will be valuable for debugging authorization issues. The error handling behavior is correctly preserved.


488-495: LGTM!

The structured logging includes appropriate context fields for media access debugging. The error handling behavior is preserved correctly.

packages/federation-sdk/src/services/room.service.ts (1)

1038-1043: LGTM! Structured logging improves observability.

The change to structured logging with all relevant context fields (roomId, branchEventId, missing) is appropriate and aids in debugging federation issues.

@rodrigok rodrigok merged commit 6614719 into main Oct 16, 2025
3 checks passed
@rodrigok rodrigok deleted the chore-improve-error-logs branch October 16, 2025 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants