Skip to content

Commit

Permalink
Convert hash key to string to support Sidekiq 7
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuk09 committed Sep 5, 2024
1 parent af1fb1b commit 8eeeeed
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
7 changes: 3 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/melvrickgoh/event_tracer" }
source 'https://rubygems.org'

# Specify your gem's dependencies in event_tracer.gemspec
gemspec

group :test do
gem 'aws-sdk-dynamodb'
gem 'debug'
gem 'nokogiri'
gem 'prometheus-client'
gem 'sidekiq'
gem 'timecop'
gem 'prometheus-client'
end
12 changes: 8 additions & 4 deletions lib/event_tracer/buffered_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def execute_payload(payloads)
filtered_payloads = filter_invalid_data(payloads)

EventTracer.warn(
loggers: %i(base),
loggers: %i[base],
action: self.class.name,
app: EventTracer::Config.config.app_name,
error: e.class.name,
Expand All @@ -46,12 +46,16 @@ def execute_payload(payloads)
)

worker.perform_async(filtered_payloads) if filtered_payloads.any?
rescue StandardError => error
raise EventTracer::ErrorWithPayload.new(error, payloads)
rescue StandardError => e
raise EventTracer::ErrorWithPayload.new(e, payloads)
end

def filter_invalid_data(payloads)
payloads.select { |payload| payload.to_json rescue false }
payloads.select do |payload|
payload.to_json
rescue StandardError
false
end
end
end
end
10 changes: 5 additions & 5 deletions lib/event_tracer/dynamo_db/default_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module DynamoDB
class DefaultProcessor
def call(log_type, action:, message:, args:)
args.merge(
timestamp: Time.now.utc.iso8601(6),
action: action,
message: message,
log_type: log_type,
app: EventTracer::Config.config.app_name
'timestamp' => Time.now.utc.iso8601(6),
'action' => action,
'message' => message,
'log_type' => log_type.to_s,
'app' => EventTracer::Config.config.app_name
)
end
end
Expand Down
24 changes: 14 additions & 10 deletions spec/event_tracer/dynamo_db/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@
let(:payload) do
{
message: 'Some message',
action: 'Testing',
log_type: :info
action: 'Testing'
}
end
let(:expected_log_worker_payload) do
[{
message: 'Some message',
action: 'Testing',
log_type: :info,
timestamp: '2020-02-09T12:34:56.000000Z',
app: EventTracer::Config.config.app_name
'message' => 'Some message',
'action' => 'Testing',
'log_type' => 'info',
'timestamp' => '2020-02-09T12:34:56.000000Z',
'app' => EventTracer::Config.config.app_name
}]
end

Expand All @@ -44,8 +43,7 @@
let(:payload) do
{
message: "\xAE",
action: 'Testing',
log_type: :info
action: 'Testing'
}
end
let(:expected_log_worker_payload) do
Expand All @@ -55,7 +53,13 @@
error: 'JSON::GeneratorError',
loggers: [:base],
app: EventTracer::Config.config.app_name,
payload: [hash_including(payload)]
payload: [
hash_including(
'log_type' => 'info',
'action' => 'Testing',
'message' => "\xAE"
)
]
}
end

Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'event_tracer/dynamo_db/logger'
require 'dry/configurable/test_interface'
require 'prometheus/client'
require 'debug'

EventTracer::Config.enable_test_interface

Expand Down

0 comments on commit 8eeeeed

Please sign in to comment.