Conversation
Add parser infrastructure to convert human-readable SemanticLogger format to JSON. Supports both nested payload structure and top-level fields. Includes test fixtures for both lograge and SemanticLogger formats.
Introduce logger_type option (:lograge or :semantic_logger) in configuration. Update railtie to configure the selected logger type. Refactor configure_lograge_automatically to configure_logger_automatically.
Update Entry and Request to extract fields from both lograge and SemanticLogger formats. Add detection for SemanticLogger request format (nested payload). Convert human-readable SemanticLogger logs to JSON when configured. Add comprehensive tests for SemanticLogger parsing.
Add --logger_type flag to CLI to specify logger format. Display logger type in TUI header. Update help documentation with usage examples.
Add comprehensive documentation for SemanticLogger support. Document both Lograge and SemanticLogger configuration options. Improve Rails stub in tests to support module_parent_name.
|
@douglas this looks great, give me a few days to review it please, thanks a lot for your contributions! Also, please run |
silva96
left a comment
There was a problem hiding this comment.
One more thing, there are a bunch of configuration validations that check for lograge, we need to do the same (conditionally) for semantic_logger
otherwise you get this:
❌ LogBench Configuration Error:
❌ Lograge is not enabled
LogBench requires lograge to be enabled in your Rails application.
...
LogBench will be disabled until this is fixed.
Sure! I'll get to it this week, thanks for the early review 👍 |
Update ConfigurationValidator to check logger_type and run appropriate validations. When using semantic_logger, users no longer see the "Lograge is not enabled" error. - Add SEMANTIC_LOGGER_ERROR_CONFIGS with relevant error messages - Validate SemanticLogger is defined and configured as Rails logger - Handle Rails 7.1+ BroadcastLogger wrapping - Add tests for validator behavior and error config structure
|
Hello @silva96! I updated the code to follow your review comment, take your time to review it as I'm not in a rush - I'll also push two other PRs:
|
|
Hey @douglas , thanks for the update. I tried it but I'm not sure how to locally configure SemanticLogger to produce json logs with the request_id as one of the keys (which is mandatory for LogBench) here's a demo log: Added this to the development.rb |
This commit adds support for SemanticLogger's JSON format output, which
requires a different configuration approach than the human-readable format.
## Background
SemanticLogger supports two output formats:
1. **Human-readable format** (default):
- Request ID appears in tags: {request_id: abc-123, ...}
- Already supported by existing REQUEST_ID_PATTERN regex
- Works out of the box (e.g., Campaigns application)
2. **JSON format** (configured with config.rails_semantic_logger.format = :json):
- Produces structured JSON output
- Requires config.log_tags to include request_id
- Request ID appears in named_tags field: {"named_tags": {"request_id": "abc-123"}}
## Changes
1. **Documentation** (README.md):
- Added official rails_semantic_logger configuration using config.log_tags
- This is the recommended approach per SemanticLogger documentation
- Reference: https://logger.rocketjob.io/rails.html
2. **Parser Enhancement** (lib/log_bench/log/entry.rb):
- Added support for extracting request_id from named_tags field
- Now checks three locations:
* Top-level request_id (Lograge format)
* payload.request_id (SemanticLogger payload format)
* named_tags.request_id (SemanticLogger JSON format with log_tags)
3. **Test Coverage** (test/test_log_bench.rb):
- Added test for named_tags request_id extraction
## Why This Change
Without this change, users who want to use SemanticLogger's JSON format
(recommended by Datadog) would not be able to correlate logs by request_id,
even after configuring log_tags according to the official documentation.
Addresses feedback from PR review: silva96#66 (comment)
Hello @silva96! Sorry, I forgot to handle the default case where an application is not configured to support I added a section in the I added more information in the commit description in case you want to review it individually. |
|
Hey @douglas i've been testing the PR using this demo app: https://github.com/silva96/test_log_bench (I created a can you clone it and use it "as is" to check until logs look the same as in the main branch, particularly improve the sidekiq and activejob integration because request id is not propagating down as we do with lograge. with your branch you get this logs in the
And with lograge (main branch) you get
To test this, clone the demo app in the same parent folder as the log_bench gem is located Example /home/projects/log_bench now cd into test_log_bench run in another tab in the same folder run: now go to http://127.0.0.1:3000/ and check log_bench UI |


Summary
Adds support for SemanticLogger format alongside the existing Lograge format. SemanticLogger is recommended by Datadog for better log ingestion and provides rich JSON-formatted logs with additional context.
Changes
Core Features
SemanticLogger Parser: New parser that converts human-readable SemanticLogger format to JSON
Dual Format Support: LogBench now seamlessly supports both formats
payloadobjectConfiguration: New
logger_typeoption:lograge(default) - maintains backward compatibility:semantic_logger- enables SemanticLogger parsingconfigure_lograge_automatically→configure_logger_automaticallyCLI Enhancement: Added
--logger_typeflaglog_bench --logger_type=semantic_loggerCode Quality Improvements
class << selfpatternDocumentation
Testing
All existing tests pass. Added 296 new tests covering:
Backward Compatibility
✅ Fully backward compatible
Example Usage
# CLI log_bench --logger_type=semantic_logger log_bench log/production.log --logger_type=lograge