Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder the exception fields to have the data field before the exception field #42

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@ jobs:
strategy:
matrix:
ruby: ['2.7', '3.0', '3.1', '3.2', '3.3']
rails: ['5.2.7', '6.0.4', '6.1.7', '7.0.8', '7.1.1']
rails: ['5.2.8', '6.0.6', '6.1.7', '7.0.8', '7.1.4', '7.2.1']
include:
- rails: '4.0.1'
- rails: '4.0.13'
ruby: '2.7'
- rails: '4.1.1'
- rails: '4.1.16'
ruby: '2.7'
- rails: '4.2.1'
- rails: '4.2.11'
ruby: '2.7'
- rails: '5.0.1'
- rails: '5.0.7'
ruby: '2.7'
- rails: '5.1.1'
- rails: '5.1.7'
ruby: '2.7'
exclude:
- rails: '7.2.1'
ruby: '2.7'
- rails: '7.2.1'
ruby: '3.0'

steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 2.6.4
* Reorder the exception fields to have the `data` field before the `exception` field

# 2.6.3
* Fix Lorekeeper::BacktraceCleaner to support BacktraceLocation

Expand Down
5 changes: 3 additions & 2 deletions lib/lorekeeper/json_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(file)
reset_state
@base_fields = { TIMESTAMP => '', MESSAGE => '', LEVEL => '' }

super(file)
super
end

def current_fields
Expand Down Expand Up @@ -77,10 +77,11 @@ def exception(exception, custom_message = nil, custom_data = nil, custom_level =
if exception.is_a?(Exception)
backtrace = clean_backtrace(exception.backtrace || [])
exception_fields = {
DATA => param_data,
EXCEPTION => "#{exception.class}: #{exception.message}",
STACK => backtrace
}
exception_fields[DATA] = param_data if param_data
exception_fields.compact!
Comment on lines 79 to +84

Choose a reason for hiding this comment

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

since you mentioned performance in the description, what about just the naive approach instead of compact?

exception_fields = {}
exception_fields[DATA] = param_data if param_data
exception_fields[EXCEPTION] = "#{exception.class}: #{exception.message}"
exception_fields[STACK] = backtrace

Choose a reason for hiding this comment

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

Hah, yeah, I was thinking of that or:

        exception_fields = {
          DATA => param_data,
          EXCEPTION => "#{exception.class}: #{exception.message}",
          STACK => backtrace
        }
        exception_fields.delete(DATA) unless param_data

Copy link
Collaborator Author

@ykitamura-mdsol ykitamura-mdsol Sep 20, 2024

Choose a reason for hiding this comment

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

it's slow

Comparison:
              before:  3252707.9 i/s
               after:  3001680.9 i/s - same-ish: difference falls within error
               naive:  2732396.6 i/s - same-ish: difference falls within error


message = param_message || exception.message
with_extra_fields(exception_fields) { log_data(log_level, message) }
Expand Down
2 changes: 1 addition & 1 deletion lib/lorekeeper/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Lorekeeper
VERSION = '2.6.3'
VERSION = '2.6.4'
end