Skip to content

Ensure Bugsnag attribution in log messages - #864

Open
aspiers wants to merge 2 commits into
bugsnag:masterfrom
aspiers:namespace-log-messages
Open

aspiers wants to merge 2 commits into
bugsnag:masterfrom
aspiers:namespace-log-messages

Conversation

@aspiers

@aspiers aspiers commented Sep 5, 2026

Copy link
Copy Markdown

Summary

Fixes #725

Testing

  • affected specs: 236 examples, 0 failures
  • logger and Rake integrations: 12 examples, 0 failures on Ruby 3.3.12
  • RuboCop: lib/bugsnag/configuration.rb clean
  • LSP diagnostics: 8 changed files, 0 errors
  • broad non-integration suite: 694 passed; one unrelated metadata truncation threshold failure reproduces identically on the untouched base checkout under Ruby 3.3.12

Prefix messages before passing them to loggers so formatters that ignore progname retain the Bugsnag namespace. Preserve lazy logging and the default output format while avoiding duplicate prefixes.
Copilot AI lite review requested due to automatic review settings September 5, 2026 23:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

It introduces an API/contract behavior change for logger progname handling and includes a small but concrete formatting bug for empty/nil messages that should be addressed before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR aims to ensure Bugsnag attribution is preserved in log output by embedding the [Bugsnag] namespace directly into log messages (rather than relying on progname), and expands spec coverage around logging behavior and session-delivery warnings.

Changes:

  • Prefix Bugsnag log messages with [Bugsnag] before passing them to the configured logger.
  • Update default logger formatter to avoid duplicate [Bugsnag] prefixes (including : variants).
  • Update/add specs to validate attribution behavior across multiple logging scenarios (on_error, breadcrumbs, sessions).
File summaries
File Description
lib/bugsnag/configuration.rb Prefixes log messages and adjusts default formatter to keep output attribution consistent/idempotent.
spec/session_tracker_spec.rb Adds coverage asserting session-delivery invalid API key warnings include [Bugsnag].
spec/on_error_spec.rb Updates expectations to assert [Bugsnag] appears in the emitted message (not via progname).
spec/integrations/logger_spec.rb Updates expected API key warning format to match new prefixing style.
spec/configuration_spec.rb Adjusts formatter expectations and adds coverage for default formatter idempotency.
spec/bugsnag_spec.rb Updates expectations for internal notify error logging to include [Bugsnag] in message body.
spec/breadcrumbs/validator_spec.rb Updates breadcrumb ignore logging to include [Bugsnag] attribution in message body.
spec/breadcrumbs/on_breadcrumb_callback_list_spec.rb Updates callback error logging expectations to include [Bugsnag] in message body.
Review details
  • Files reviewed: 8/8 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/bugsnag/configuration.rb Resolved
Comment thread lib/bugsnag/configuration.rb Resolved
Restore PROG_NAME as the logger progname argument so consumers that read
progname separately from the message (structured logging, custom formatters)
keep the previous contract. The message prefix still guarantees attribution
for formatters that discard progname, so both audiences are served.

Return the bare prefix for nil or empty messages instead of "[Bugsnag] ",
which left a trailing space and was inconsistent with the idempotency rule
that a message already starting with the prefix is passed through unchanged.
@hannah-smartbear

Copy link
Copy Markdown

Hi @aspiers,

Thanks for taking the time to raise this PR!

Our engineers will take a look, and leave any comments or updates on this PR accordingly.

This branch has not been deployed

No deployments
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.

Error Message: "Not delivering sessions due to an invalid api_key" needs to clarify it's coming from Bugsnag Gem

3 participants