diff --git a/Gemfile b/Gemfile index 6e0fa0b..74181e8 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/lib/event_tracer/buffered_logger.rb b/lib/event_tracer/buffered_logger.rb index 23e9364..76268bf 100644 --- a/lib/event_tracer/buffered_logger.rb +++ b/lib/event_tracer/buffered_logger.rb @@ -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, @@ -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 diff --git a/lib/event_tracer/dynamo_db/default_processor.rb b/lib/event_tracer/dynamo_db/default_processor.rb index 5cc73db..5c77b07 100644 --- a/lib/event_tracer/dynamo_db/default_processor.rb +++ b/lib/event_tracer/dynamo_db/default_processor.rb @@ -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 diff --git a/spec/event_tracer/dynamo_db/logger_spec.rb b/spec/event_tracer/dynamo_db/logger_spec.rb index 9bf624e..57f1957 100644 --- a/spec/event_tracer/dynamo_db/logger_spec.rb +++ b/spec/event_tracer/dynamo_db/logger_spec.rb @@ -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 @@ -44,8 +43,7 @@ let(:payload) do { message: "\xAE", - action: 'Testing', - log_type: :info + action: 'Testing' } end let(:expected_log_worker_payload) do @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5b87cc3..b5c4c9b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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