Skip to content

Properly format log record & report logged extras to rollbar#488

Open
terencehonles wants to merge 1 commit intorollbar:masterfrom
terencehonles:support-logging-extra-keyword-argument
Open

Properly format log record & report logged extras to rollbar#488
terencehonles wants to merge 1 commit intorollbar:masterfrom
terencehonles:support-logging-extra-keyword-argument

Conversation

@terencehonles
Copy link
Contributor

@terencehonles terencehonles commented Feb 27, 2026

Description of the change

This change passes the log record through the configured formatter, if any, and reports any non blocklisted logging record keys as extra data. This allows supporting Python logging's extra keyword argument which sets additional properties on the log record.

Please include a summary of the change and which issues are fixed.
Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Maintenance
  • New release

Related issues

Shortcut stories and GitHub issues (delete irrelevant)

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • "Ready for review" label attached to the PR and reviewers assigned
  • Issue from task tracker has a link to this pull request
  • Changes have been reviewed by at least one other engineer

This change passes the log record through the configured formatter, if
any, and reports any non blocklisted logging record keys as extra data.
This allows supporting Python logging's `extra` keyword argument which
sets additional properties on the log record.
@terencehonles terencehonles force-pushed the support-logging-extra-keyword-argument branch from 7395329 to 53b3243 Compare February 27, 2026 13:06
self.rollbar_handler = RollbarHandler(_test_access_token, _test_environment)
self.rollbar_handler.setLevel(logging.WARNING)

logger.addHandler(self.rollbar_handler)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since loggers are global, this was attaching more and more handlers with potentially conflicting config. I removed the _create_logger method and inlined it in the setUp and provided the correct tearDown to ensure the handlers were removed when the test finishes.

@terencehonles terencehonles mentioned this pull request Feb 27, 2026
12 tasks
@terencehonles
Copy link
Contributor Author

@danielmorell when you get a chance, I fixed a few open issues if you can review the changes.

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.

RollbarHandler should include extra data from LogRecords automatically (or provide a switch to enable that) Unable to use a custom log formatter

1 participant