Skip to content

Conversation

@sampaiodiego
Copy link
Member

@sampaiodiego sampaiodiego commented Dec 5, 2025

Proposed changes (including videos or screenshots)

We were completely missing the errors the way we were logging errors.

See this code as an example of why the changes are needed:

const lero = new Logger('lero');
try {
	const foo = { a: 1, b: 2 };
	const bar = 'some string';

	lero.warn('foo wrong', foo);
	lero.warn({ foo, msg: 'foo correct' });

	lero.warn('bar wrong', bar);
	lero.warn({ bar, msg: 'bar correct' });

	// @ts-ignore
	console.log(xxx);
} catch (error) {
	lero.error('wrong error:', error);
	lero.error(error, 'correct error');
}

This produces the following production logs:

{"level":40,"time":"2025-12-05T18:33:54.867Z","pid":86382,"hostname":"local","name":"lero","msg":"foo wrong {\"a\":1,\"b\":2}"}
{"level":40,"time":"2025-12-05T18:33:54.867Z","pid":86382,"hostname":"local","name":"lero","foo":{"a":1,"b":2},"msg":"foo correct"}
{"level":40,"time":"2025-12-05T18:33:54.867Z","pid":86382,"hostname":"local","name":"lero","msg":"bar wrong 'some string'"}
{"level":40,"time":"2025-12-05T18:33:54.867Z","pid":86382,"hostname":"local","name":"lero","bar":"some string","msg":"bar correct"}
{"level":50,"time":"2025-12-05T18:33:54.867Z","pid":86382,"hostname":"local","name":"lero","msg":"wrong error: {}"}
{"level":50,"time":"2025-12-05T18:33:54.867Z","pid":86382,"hostname":"local","name":"lero","err":{"type":"ReferenceError","message":"xxx is not defined","stack":"ReferenceError: xxx is not defined\n    at Object.<anonymous> (/Users/diegosampaio/dev/Rocket.Chat/ee/packages/federation-matrix/src/FederationMatrix.ts:149:14)\n    at Module.<anonymous> (node:internal/modules/cjs/loader:1688:14)\n    at Module.Mp._compile (/tools/static-assets/server/runtime.js:91:21)\n    at Object.Module._extensions..js (/tools/static-assets/server/runtime.js:125:21)\n    at Module.<anonymous> (node:internal/modules/cjs/loader:1423:32)\n    at Module.Mp.load (/tools/static-assets/server/runtime.js:35:31)\n    at Function._load (node:internal/modules/cjs/loader:1246:12)\n    at TracingChannel.traceSync (node:diagnostics_channel:322:14)\n    at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)\n    at Module.<anonymous> (node:internal/modules/cjs/loader:1445:12)\n    at Module.mod.require (/Users/diegosampaio/.meteor/packages/meteor-tool/.3.3.1.1ppfc33ygtz++os.osx.arm64+web.browser+web.browser.legacy+web.cordova/mt-os.osx.arm64/dev_bundle/server-lib/node_modules/@meteorjs/reify/lib/runtime/index.js:30:33)\n    at require (node:internal/modules/helpers:135:16)\n    at Object.<anonymous> (/Users/diegosampaio/dev/Rocket.Chat/ee/packages/federation-matrix/src/index.ts:3:1)\n    at Module.<anonymous> (node:internal/modules/cjs/loader:1688:14)\n    at Module.Mp._compile (/tools/static-assets/server/runtime.js:91:21)\n    at Object.Module._extensions..js (/tools/static-assets/server/runtime.js:125:21)"},"msg":"correct error"}

as you can see this is what we were seeing: "msg":"wrong error: {}"}

Issue(s)

FB-133

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • Refactor
    • Standardized error logging patterns across federation services with improved structured logging for enhanced consistency and observability in error handling.

✏️ Tip: You can customize this high-level summary in your review settings.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Dec 5, 2025

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Dec 5, 2025

⚠️ No Changeset found

Latest commit: 4301ee0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 5, 2025

Walkthrough

This PR standardizes error logging patterns across the federation-matrix package by converting logger.error calls from message-first to error-first argument ordering and replacing plain string logs with structured log objects containing contextual identifiers and message fields.

Changes

Cohort / File(s) Summary
Event handlers
ee/packages/federation-matrix/src/events/edu.ts, ee/packages/federation-matrix/src/events/member.ts, ee/packages/federation-matrix/src/events/message.ts, ee/packages/federation-matrix/src/events/reaction.ts
Swapped error logging argument order from (message, error) to (error, message); replaced plain string error messages with structured log objects containing identifiers and msg fields
Core federation
ee/packages/federation-matrix/src/FederationMatrix.ts
Standardized error logging across try-catch blocks by swapping argument order and converting to structured log objects with contextual fields (roomId, messageId, etc.)
API layer
ee/packages/federation-matrix/src/api/_matrix/invite.ts
Converted logger.error invocations in runWithBackoff retry logic to pass error object first, followed by descriptive message string
Media service
ee/packages/federation-matrix/src/services/MatrixMediaService.ts
Standardized logging across file handling paths by inverting error argument order and introducing structured objects for invalid MXC URI contexts

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10–15 minutes

  • Rationale: Changes follow a consistent, homogeneous pattern across multiple files (argument order swap + structured logging) with no functional or control-flow alterations. Repetitive nature of edits reduces per-file review complexity despite the 7-file spread.

Possibly related PRs

  • RocketChat/Rocket.Chat#37116: Modifies runWithBackoff-related code and logging in the same invite.ts file; complements this PR's logging standardization in retry logic.
  • RocketChat/Rocket.Chat#37035: Related federation-matrix logging and API standardization changes across the same event and service files.

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • rodrigok
  • ggazzo
  • ricardogarim

Poem

🐰 Logs now tell their tales so bright,
Errors first, then messages light,
Structured fields dance in the night,
Federation's logging—finally right! ✨📝

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'chore(federation): fix error logs' is directly related to the main change: the PR fixes error logging by correcting the argument order in logger.error() calls across multiple federation files.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ 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-federation-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.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

📦 Docker Image Size Report

📈 Changes

Service Current Baseline Change Percent
sum of all images 1.2GiB 1.2GiB +12MiB
rocketchat 359MiB 347MiB +12MiB
omnichannel-transcript-service 132MiB 132MiB -239B
queue-worker-service 132MiB 132MiB +108B
ddp-streamer-service 126MiB 126MiB -801B
account-service 113MiB 113MiB +1.6KiB
stream-hub-service 111MiB 111MiB -504B
authorization-service 111MiB 111MiB +1.0KiB
presence-service 111MiB 111MiB +754B

📊 Historical Trend

---
config:
  theme: "dark"
  xyChart:
    width: 900
    height: 400
---
xychart
  title "Image Size Evolution by Service (Last 30 Days + This PR)"
  x-axis ["11/15 22:28", "11/16 01:28", "11/17 23:50", "11/18 22:53", "11/19 23:02", "11/21 16:49", "11/24 17:34", "11/27 22:32", "11/28 19:05", "12/01 23:01", "12/02 21:57", "12/03 21:00", "12/04 18:17", "12/05 15:23", "12/05 18:55 (PR)"]
  y-axis "Size (GB)" 0 --> 0.5
  line "account-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11]
  line "authorization-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11]
  line "ddp-streamer-service" [0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12]
  line "omnichannel-transcript-service" [0.14, 0.14, 0.14, 0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13]
  line "presence-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11]
  line "queue-worker-service" [0.14, 0.14, 0.14, 0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13]
  line "rocketchat" [0.36, 0.36, 0.35, 0.35, 0.35, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.35]
  line "stream-hub-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11]
Loading

Statistics (last 14 days):

  • 📊 Average: 1.5GiB
  • ⬇️ Minimum: 1.2GiB
  • ⬆️ Maximum: 1.6GiB
  • 🎯 Current PR: 1.2GiB
ℹ️ About this report

This report compares Docker image sizes from this build against the develop baseline.

  • Tag: pr-37706
  • Baseline: develop
  • Timestamp: 2025-12-05 18:55:57 UTC
  • Historical data points: 14

Updated: Fri, 05 Dec 2025 18:55:57 GMT

@sampaiodiego sampaiodiego force-pushed the chore-federation-error-logs branch from 5ffdd08 to 4301ee0 Compare December 5, 2025 18:42
@sampaiodiego sampaiodiego marked this pull request as ready for review December 5, 2025 19:09
@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.78%. Comparing base (48953d2) to head (4301ee0).
⚠️ Report is 12 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #37706      +/-   ##
===========================================
- Coverage    67.79%   67.78%   -0.02%     
===========================================
  Files         3449     3449              
  Lines       114030   114030              
  Branches     20963    20963              
===========================================
- Hits         77305    77292      -13     
- Misses       34606    34627      +21     
+ Partials      2119     2111       -8     
Flag Coverage Δ
e2e 57.22% <ø> (-0.05%) ⬇️
e2e-api 42.13% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 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.

@sampaiodiego sampaiodiego added this to the 7.14.0 milestone Dec 8, 2025
@sampaiodiego sampaiodiego added the stat: QA assured Means it has been tested and approved by a company insider label Dec 8, 2025
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Dec 8, 2025
@sampaiodiego sampaiodiego merged commit 062e464 into develop Dec 8, 2025
57 checks passed
@sampaiodiego sampaiodiego deleted the chore-federation-error-logs branch December 8, 2025 14:12
@coderabbitai coderabbitai bot mentioned this pull request Dec 24, 2025
@dougfabris dougfabris modified the milestones: 7.14.0, 8.0.0 Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants