Skip to content

fix(recording): log to stdout when not running under the systemd journal - #26111

Merged
TiagoJacobs merged 1 commit into
bigbluebutton:v4.0.x-developfrom
imdt-claudiop:fix/rap-logger-without-journald
Oct 21, 2026
Merged

TiagoJacobs merged 1 commit into
bigbluebutton:v4.0.x-developfrom
imdt-claudiop:fix/rap-logger-without-journald

Conversation

@imdt-claudiop

@imdt-claudiop imdt-claudiop commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

The recording processing services log only through Journald::Logger (BigBlueButton.logger in record-and-playback/core/lib/recordandplayback.rb, and the caption inbox in rap-caption-inbox.rb). Without a journal, as in a container, Journald::Logger drops every line without an error (sd_journal_sendv returns 0 when the socket is missing), so rap-starter, the resque worker and the caption inbox run silently.

This adds BigBlueButton.system_logger(identifier). It returns the same Journald::Logger when JOURNAL_STREAM is set, which systemd does for every unit whose stdout/stderr goes to the journal (systemd.exec(5) documents it for exactly this upgrade to the native journal protocol). Otherwise it returns a StdoutLogger on a synced stdout, tagged with the identifier, so the container runtime collects the lines. The rap units use the default StandardOutput, so package installs keep logging to journald exactly as before.

StdoutLogger is a small Logger subclass that implements the two journald-specific methods the recording code calls: tag (the fields are appended to the lines logged inside the block and removed after it) and exception (class, message and backtrace). rap-caption-inbox.rb uses both, so a plain Logger would raise NoMethodError on the first caption file.

Closes Issue(s)

None.

Motivation

Found while running the recording services in containers: rap-starter and the worker produced no output at all, which made processing failures impossible to follow. Container setups patch this line today (for example, the recordings mod of bigbluebutton/docker replaces the journald logger in both files with a sed).

How to test

  1. In an environment without systemd (e.g. a ruby container with the record-and-playback gems), from record-and-playback/core:

    ruby -Ilib -e 'require "recordandplayback"; BigBlueButton.logger.info("hello")'
    
    • Before: prints nothing (the logger is a Journald::Logger and the line is lost).
    • After: prints I, [...] INFO -- bbb-rap: hello.

    The caption inbox logger keeps its tags:

    ruby -Ilib -e 'require "recordandplayback"; l = BigBlueButton.system_logger("bbb-rap-caption-inbox"); l.tag(record_id: "abc") { l.info("caption processed") }'
    

    prints INFO -- bbb-rap-caption-inbox: caption processed record_id=abc.

  2. On a regular install the services run under systemd with JOURNAL_STREAM set and keep logging to journald: journalctl -t bbb-rap shows the lines as before. With JOURNAL_STREAM=8:1 set, ruby -Ilib -e 'require "recordandplayback"; p BigBlueButton.logger.class' prints Journald::Logger.

  3. bundle exec rake test in record-and-playback/core: test_logger.rb passes (5 runs).

More

rake test also reports a failure in TestEvents#test_enforce_cut_lengths_short_cut_start (edl/test_video.rb); it fails the same way on the base branch and is unrelated to this change.

  • Added/updated documentation (not needed: package installs behave as before)

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 49bf0e1b-9b30-43f4-9f20-1e09015a3bd9
📥 Commits

Reviewing files that changed from the base of the PR and between b7a3f64 and 7e6fc02.

📒 Files selected for processing: 3
  • record-and-playback/core/lib/recordandplayback.rb
  • record-and-playback/core/scripts/rap-caption-inbox.rb
  • record-and-playback/core/test/recordandplayback/test_logger.rb

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Walkthrough

The shared logger selects Journald when JOURNAL_STREAM is present. Otherwise, it creates a synchronized stdout logger that supports temporary tags and exception details. The caption inbox now uses the shared logger factory. Tests cover logger selection, synchronized output, tags, and exception logging.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Inbox as rap-caption-inbox
  participant Logger as BigBlueButton.system_logger
  participant Env as ENV
  participant Journald as Journald::Logger
  participant Stdout as StdoutLogger
  Inbox->>Logger: request logger with identifier
  Logger->>Env: check JOURNAL_STREAM
  alt JOURNAL_STREAM is present
    Logger->>Journald: create logger
    Journald-->>Inbox: return logger
  else JOURNAL_STREAM is absent
    Logger->>Stdout: enable synchronized stdout and create logger
    Stdout-->>Inbox: return logger
  end
Loading

Suggested reviewers: germanocaumo, tiagojacobs

Merge Risk: ⚪ Minimal · up to 7e6fc

Logging falls back to stdout when JOURNAL_STREAM is unset and keeps journald under systemd. No merge-blocking risk was found.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: falling back to stdout when the systemd journal is unavailable.
Description check Passed The description directly explains the logging fallback, journald preservation, affected services, tests, and known unrelated failures.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@TiagoJacobs TiagoJacobs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, the diagnosis is right: sd_journal_sendv returns 0 when the socket is missing, so the lines are lost silently. Two changes before this can go in.

1. Detect the journal through JOURNAL_STREAM instead of probing the socket path.

/run/systemd/journal/socket is a private constant of sd_journal_sendv, not an interface. systemd sets JOURNAL_STREAM for every unit whose stdout/stderr goes to the journal, and systemd.exec(5) documents it precisely for this purpose: letting a service upgrade to the native journal protocol. All three rap units use the default StandardOutput, so package installs keep the exact same Journald::Logger; without systemd we log to stdout. No copied path, no new config, and the journald_socket: keyword exists only for the tests and can go away (the test just sets the variable):

def self.system_logger(identifier)
  return Journald::Logger.new(identifier) if ENV.key?('JOURNAL_STREAM')

  $stdout.sync = true
  StdoutLogger.new($stdout, progname: identifier)
end

2. The stdout fallback has to implement tag and exception.

rap-caption-inbox.rb calls logger.tag(record_id: ...) do ... end (line 70) and logger.exception(e) (line 153). Plain Logger has neither, so in a container the first caption file raises NoMethodError outside any rescue and kills the inbox. These are the only journald-specific methods the record-and-playback code uses, so a small subclass is enough:

class StdoutLogger < Logger
  def tag(**fields)
    saved, @tags = @tags, (@tags || {}).merge(fields)
    yield
  ensure
    @tags = saved
  end

  def exception(e)
    error("#{e.class}: #{e.message}\n#{e.backtrace&.join("\n")}")
  end

  private

  def format_message(severity, time, progname, msg)
    msg = "#{msg} #{@tags.map { |k, v| "#{k}=#{v}" }.join(' ')}" if @tags&.any?
    super
  end
end

Tests: keep the stdout and sync cases, replace the UNIX socket case with JOURNAL_STREAM set, and add tag (fields present inside the block, gone after it) and exception. Set or delete JOURNAL_STREAM explicitly in each test and restore it in teardown, so the result does not depend on where the suite runs.

@imdt-claudiop
imdt-claudiop force-pushed the fix/rap-logger-without-journald branch from d90c6e6 to 8aa19de Compare October 20, 2026 21:57
@imdt-claudiop imdt-claudiop changed the title fix(recording): log to stdout when there is no journald socket fix(recording): log to stdout when not running under the systemd journal Oct 20, 2026
@imdt-claudiop

Copy link
Copy Markdown
Contributor Author

Thanks, both applied in 8aa19de, with your code as written:

  1. system_logger now returns Journald::Logger when JOURNAL_STREAM is set and a synced stdout logger otherwise. The socket probe, the JOURNALD_SOCKET constant and the journald_socket: keyword are gone (core/lib/recordandplayback.rb).
  2. The stdout fallback is BigBlueButton::StdoutLogger < Logger, with tag and exception exactly as you suggested, so the logger.tag(record_id: ...) and logger.exception(e) calls in rap-caption-inbox.rb work in a container.

Tests (core/test/recordandplayback/test_logger.rb): the stdout and sync cases stay, the UNIX socket case is now a JOURNAL_STREAM case, and there are new cases for tag (fields present inside the block, gone after it) and exception (class, message and backtrace). Each test sets or deletes JOURNAL_STREAM and the teardown restores it together with $stdout. Before this change the new cases failed (NoMethodError for tag and exception, and stdout chosen with JOURNAL_STREAM set). Now test_logger.rb passes with 5 runs; the full rake test has 38 runs and only the known TestEvents#test_enforce_cut_lengths_short_cut_start failure, which also fails on the base branch.

I also rebased on the current v4.0.x-develop and updated the description to match.

@TiagoJacobs TiagoJacobs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this is what I had in mind. Two small things and I think it can go in.

The sync test does not test anything: StringIO#sync always returns true, so it passes with or without the $stdout.sync = true line. Swap the StringIO for a File in that one test, sync defaults to false there and flips to true after system_logger:

def test_stdout_logger_is_synced
  ENV.delete('JOURNAL_STREAM')
  $stdout = File.open(File::NULL, 'w')
  BigBlueButton.system_logger('bbb-rap-test')
  assert($stdout.sync, 'stdout must be synced so lines are not lost when the process is killed')
end

(teardown already restores $stdout.)

I'd rather fix the two RuboCop offenses than mention them in the description, they are trivial:

def tag(**fields)
  saved = @tags
  @tags = (saved || {}).merge(fields)
  yield
ensure
  @tags = saved
end

def exception(exc)
  error("#{exc.class}: #{exc.message}\n#{exc.backtrace&.join("\n")}")
end

Then drop the "More" paragraph about RuboCop, and the per-file bullet list in the description too, the diff already says that. Please squash into one commit, the intermediate socket-probe version does not need to be in history, and mark the PR ready for review so CodeRabbit runs on it.

One thing I noticed but would leave alone: an exception object logged inside a tag block loses the class and backtrace, because the tags are appended before the formatter sees it. Nothing calls it that way today.

The recording services (rap-starter, the resque worker, the caption inbox)
log only through Journald::Logger, which drops every line without an error
when there is no journal, as in a container.

BigBlueButton.system_logger returns the same Journald::Logger when
JOURNAL_STREAM is set, which systemd does for every unit whose stdout/stderr
goes to the journal (systemd.exec(5)), so package installs keep logging to
journald. Otherwise it returns a StdoutLogger on a synced stdout: a Logger
subclass with the journald-specific methods the recording code calls, tag
(fields appended to the lines inside the block) and exception.
BigBlueButton.logger and rap-caption-inbox.rb use it.
@imdt-claudiop
imdt-claudiop force-pushed the fix/rap-logger-without-journald branch from 8aa19de to 7e6fc02 Compare October 20, 2026 23:05
@imdt-claudiop

Copy link
Copy Markdown
Contributor Author

Done, squashed into a single commit on top of the current v4.0.x-develop:

  • The sync test now uses your File::NULL version. I checked that it fails when the $stdout.sync = true line is removed and passes with it.
  • tag and exception(exc) use your code; RuboCop reports no offenses in the changed code now, and the RuboCop note is gone from the description, along with the per-file list.

test_logger.rb passes with 5 runs; the full rake test has 38 runs with only the known TestEvents#test_enforce_cut_lengths_short_cut_start failure. Agreed on leaving the exception-object-inside-a-tag-block case alone for now.

@TiagoJacobs

Copy link
Copy Markdown
Member

Verified 7e6fc02 locally: the 5 logger tests pass, the sync test fails when the sync line is removed, no RuboCop offenses on the changed lines, and the full suite fails the same tests as the base branch. The only item left from my review is marking the PR ready for review so CodeRabbit runs; I'll approve once that and the CI run are through.

@TiagoJacobs

Copy link
Copy Markdown
Member

The CI failure is the Playwright screenshare test "Hidden presentation stays hidden after screenshare ends when the slide has annotations" timing out in the legacy media job, flagged as flaky by the report itself and unrelated to this change (the same job passed on the previous commit of this PR). I re-ran the failed job.

@github-actions

Copy link
Copy Markdown

✅ Automated tests have passed!

@TiagoJacobs
TiagoJacobs marked this pull request as ready for review October 21, 2026 00:31

@TiagoJacobs TiagoJacobs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved at 7e6fc02. Verified locally: the 5 logger tests pass, the sync test fails without the sync line, no RuboCop offenses on the changed lines, and the full suite fails the same tests as the base branch. CI is green after re-running the flaky screenshare job. I marked the PR ready for review so CodeRabbit runs on it; if it reports anything substantive, please address it before merge.

@TiagoJacobs
TiagoJacobs merged commit 59d39ea into bigbluebutton:v4.0.x-develop Oct 21, 2026
59 of 60 checks passed
TiagoJacobs added a commit that referenced this pull request Oct 21, 2026
…-graphql-41

[4.1 port] recording and GraphQL Redis fixes from v4.0.x-develop (#26109 #26110 #26111 #26112)
@antobinary antobinary added this to the Release 4.0 milestone Oct 21, 2026
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.

3 participants