semantic_logger_ecs_addon 0.1.8 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d97e95704e7b702f7b074ca810b708b2ed4525f724d513aa8c1a85b96b0946b4
4
- data.tar.gz: d3d1a40446ac60bfa744475a08bb7a1e788d886bb540a09cf015a61ebb8ee3c4
3
+ metadata.gz: 1e0a6e782e73897614ae1bd76e9b7c59f94d28a3a60e2cfbf22ed2209e505ac7
4
+ data.tar.gz: 47eed3029664c86ebd8bac1dd16146b9685787c064e6048af62f28e4cfc43df5
5
5
  SHA512:
6
- metadata.gz: 6b71ec9ad44a55906324767394a92c622b69f877c80d4d8b2b7460cd10247ae6ec29f6eb438a803598160e37fc1f3a86d80e47d7d186998fcce0b17f4920db52
7
- data.tar.gz: 7b1c09644d4618f74a4e487468dc8059986221bc013f1024ef6b9fd33bb436237486612483b6247823b89bd3644959ecf898431af41fce0b029c2981319d94b7
6
+ metadata.gz: 767d6b40db82d541e7292ac2467f4d355e6dacdac7102bb1b7fe0576337d41129e2f70766ab0bb7d5729702a7ae8479708947489e4c1d892af03ca67de892835
7
+ data.tar.gz: 4777970e9fd90fb3e0706305548364e3a3d4ac1974536eb45df1627c73f12598d28fd2ce944f2bfdf26ae8149a47f5ddf92ab27ac6c88382ac99566d71837974
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,91 +1,89 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if defined?(Sequel) && defined? ActiveSupport::LogSubscriber
4
- module RailsSemanticLogger
5
- module Sequel
6
- class LogSubscriber < ActiveSupport::LogSubscriber
7
- class << self
8
- attr_reader :logger
9
- end
10
-
11
- def self.runtime= value
12
- # ::ActiveRecord::RuntimeRegistry.sql_runtime = value
13
- RequestStore.store[:sql_runtime] = value
14
- end
3
+ module RailsSemanticLogger
4
+ module Sequel
5
+ class LogSubscriber < ActiveSupport::LogSubscriber
6
+ class << self
7
+ attr_reader :logger
8
+ end
15
9
 
16
- def self.runtime
17
- # ::ActiveRecord::RuntimeRegistry.sql_runtime ||= 0
18
- RequestStore.fetch(:sql_runtime) { 0 }
19
- end
10
+ def self.runtime= value
11
+ # ::ActiveRecord::RuntimeRegistry.sql_runtime = value
12
+ RequestStore.store[:sql_runtime] = value
13
+ end
20
14
 
21
- def self.count= value
22
- RequestStore.store[:sql_count] = value
23
- end
15
+ def self.runtime
16
+ # ::ActiveRecord::RuntimeRegistry.sql_runtime ||= 0
17
+ RequestStore.fetch(:sql_runtime) { 0 }
18
+ end
24
19
 
25
- def self.count
26
- RequestStore.fetch(:sql_count) { 0 }
27
- end
20
+ def self.count= value
21
+ RequestStore.store[:sql_count] = value
22
+ end
28
23
 
29
- def self.reset_runtime
30
- previous = runtime
31
- self.runtime = 0
32
- previous
33
- end
24
+ def self.count
25
+ RequestStore.fetch(:sql_count) { 0 }
26
+ end
34
27
 
35
- def self.reset_count
36
- previous = count
37
- self.count = 0
38
- previous
39
- end
28
+ def self.reset_runtime
29
+ previous = runtime
30
+ self.runtime = 0
31
+ previous
32
+ end
40
33
 
41
- def sql event
42
- self.class.runtime += event.duration
43
- self.class.count += 1
44
- return unless logger.debug?
34
+ def self.reset_count
35
+ previous = count
36
+ self.count = 0
37
+ previous
38
+ end
45
39
 
46
- payload = event.payload
47
- name = payload[:name]
40
+ def sql event
41
+ self.class.runtime += event.duration
42
+ self.class.count += 1
43
+ return unless logger.debug?
48
44
 
49
- log_payload = {sql: payload[:sql].squeeze(" ")}
50
- log_payload[:binds] = bind_values payload unless (payload[:binds] || []).empty?
51
- log_payload[:allocations] = event.allocations if event.respond_to? :allocations
52
- log_payload[:cached] = event.payload[:cached]
45
+ payload = event.payload
46
+ name = payload[:name]
53
47
 
54
- log = {message: name, payload: log_payload, duration: event.duration}
48
+ log_payload = {sql: payload[:sql].squeeze(" ")}
49
+ log_payload[:binds] = bind_values payload unless (payload[:binds] || []).empty?
50
+ log_payload[:allocations] = event.allocations if event.respond_to? :allocations
51
+ log_payload[:cached] = event.payload[:cached]
55
52
 
56
- # Log the location of the query itself.
57
- if logger.send(:level_index) >= SemanticLogger.backtrace_level_index
58
- log[:backtrace] = SemanticLogger::Utils.strip_backtrace caller
59
- end
53
+ log = {message: name, payload: log_payload, duration: event.duration}
60
54
 
61
- logger.debug log
55
+ # Log the location of the query itself.
56
+ if logger.send(:level_index) >= SemanticLogger.backtrace_level_index
57
+ log[:backtrace] = SemanticLogger::Utils.strip_backtrace caller
62
58
  end
63
59
 
64
- private
60
+ logger.debug log
61
+ end
65
62
 
66
- @logger = SemanticLogger["Sequel"]
63
+ private
67
64
 
68
- # When multiple values are received for a single bound field, it is converted into an array
69
- def add_bind_value binds, key, value
70
- key = key.downcase.to_sym unless key.nil?
71
- value = (Array(binds[key]) << value) if binds.key? key
72
- binds[key] = value
73
- end
65
+ @logger = SemanticLogger["Sequel"]
74
66
 
75
- def logger
76
- self.class.logger
77
- end
67
+ # When multiple values are received for a single bound field, it is converted into an array
68
+ def add_bind_value binds, key, value
69
+ key = key.downcase.to_sym unless key.nil?
70
+ value = (Array(binds[key]) << value) if binds.key? key
71
+ binds[key] = value
72
+ end
78
73
 
79
- def bind_values payload
80
- binds = {}
81
- binds = " " + payload[:binds].map { |col, v| [col.name, v] }
82
- .inspect
83
- payload[:binds].each { |col, value| add_bind_value binds, col.name, value }
84
- binds
85
- end
74
+ def logger
75
+ self.class.logger
76
+ end
77
+
78
+ def bind_values payload
79
+ binds = {}
80
+ binds = " " + payload[:binds].map { |col, v| [col.name, v] }
81
+ .inspect
82
+ payload[:binds].each { |col, value| add_bind_value binds, col.name, value }
83
+ binds
86
84
  end
87
85
  end
88
86
  end
89
-
90
- RailsSemanticLogger::Sequel::LogSubscriber.attach_to :sequel
91
87
  end
88
+
89
+ RailsSemanticLogger::Sequel::LogSubscriber.attach_to :sequel
@@ -164,7 +164,7 @@ module SemanticLoggerEcsAddon
164
164
  end
165
165
 
166
166
  def format_payload
167
- if log.payload.respond_to?(:empty?) && !log.payload.empty?
167
+ if log.payload.respond_to?(:empty?) && !log.payload.empty? && log.payload.respond_to?(:has_key?)
168
168
  self.formatted_payload = Utils::Hash[**log.payload]
169
169
 
170
170
  rack_extract
@@ -203,7 +203,7 @@ module SemanticLoggerEcsAddon
203
203
  def apm_agent_present_and_running?
204
204
  return false unless defined?(::ElasticAPM)
205
205
 
206
- ElasticAPM.running?
206
+ ::ElasticAPM.running?
207
207
  end
208
208
  end
209
209
  end
@@ -5,7 +5,7 @@ module SemanticLoggerEcsAddon
5
5
  module Identity
6
6
  NAME = "semantic_logger_ecs_addon"
7
7
  LABEL = "Semantic Logger Ecs Addon"
8
- VERSION = "0.1.8"
8
+ VERSION = "0.1.12"
9
9
  VERSION_LABEL = "#{LABEL} #{VERSION}"
10
10
  SUMMARY = "A semantic logger formatter that formats the logs according to Elastic Common Schema, adds APM trace data if ElasticAPM is enabled and instruments sequel logs for rails if available."
11
11
  end
@@ -0,0 +1,3 @@
1
+ require "rails_semantic_logger/sequel/log_subscriber" if defined? ActiveSupport::LogSubscriber
2
+ require "sequel/database" if defined?(ActiveSupport::Notifications)
3
+ require "sequel/railties/controller_runtime" if defined?(ActionController)
@@ -2,15 +2,11 @@
2
2
 
3
3
  require "pathname"
4
4
  require "zeitwerk"
5
- # if defined?(Sequel)
6
- # if defined? ActiveSupport::LogSubscriber
7
- # require_relative "rails_semantic_logger/sequel/log_subscriber"
8
- # end
9
- # require_relative "sequel/database" if defined?(ActiveSupport::Notifications)
10
- # require_relative "sequel/railties/controller_runtime" if defined?(ActionController)
11
- # end
12
5
 
13
6
  loader = Zeitwerk::Loader.for_gem
7
+ loader.ignore "#{__dir__}/rails_semantic_logger"
8
+ loader.ignore "#{__dir__}/sequel"
9
+ loader.ignore "#{__dir__}/semantic_logger_ecs_addon/sequel.rb"
14
10
  loader.setup
15
11
 
16
12
  # Main namespace.
@@ -1,35 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if defined?(Sequel) && defined?(ActiveSupport::Notifications)
4
- require "sequel/database/logging"
3
+ require "sequel/database/logging"
5
4
 
6
- module Sequel
7
- class Database
8
- def log_connection_yield sql, conn, args = nil
9
- log_connection_info = (connection_info conn if conn && log_connection_info)
10
- log_args = ("; #{args.inspect}" if args)
11
- sql_for_log = "#{log_connection_info}#{sql}#{log_args}"
12
- start = Time.now
13
- begin
14
- ::ActiveSupport::Notifications.instrument(
15
- "sql.sequel",
16
- sql: sql,
17
- name: self.class,
18
- binds: args
19
- ) do
20
- yield
21
- end
22
- rescue StandardError => error
23
- log_exception error, sql_for_log unless @loggers.empty?
24
- raise
25
- ensure
26
- log_duration Time.now - start, sql_for_log unless error || @loggers.empty?
5
+ module Sequel
6
+ class Database
7
+ def log_connection_yield sql, conn, args = nil
8
+ log_connection_info = (connection_info conn if conn && log_connection_info)
9
+ log_args = ("; #{args.inspect}" if args)
10
+ sql_for_log = "#{log_connection_info}#{sql}#{log_args}"
11
+ start = Time.now
12
+ begin
13
+ ::ActiveSupport::Notifications.instrument(
14
+ "sql.sequel",
15
+ sql: sql,
16
+ name: self.class,
17
+ binds: args
18
+ ) do
19
+ yield
27
20
  end
21
+ rescue StandardError => error
22
+ log_exception error, sql_for_log unless @loggers.empty?
23
+ raise
24
+ ensure
25
+ log_duration Time.now - start, sql_for_log unless error || @loggers.empty?
28
26
  end
27
+ end
29
28
 
30
- def log_yield sql, args = nil, &block
31
- log_connection_yield(sql, nil, args, &block)
32
- end
29
+ def log_yield sql, args = nil, &block
30
+ log_connection_yield(sql, nil, args, &block)
33
31
  end
34
32
  end
35
33
  end
@@ -1,65 +1,63 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if defined?(Sequel) && defined?(ActionController)
4
- require "active_support/core_ext/module/attr_internal"
5
- unless defined?(RailsSemanticLogger::Sequel::LogSubscriber)
6
- require_relative "../../rails_semantic_logger/sequel/log_subscriber"
7
- end
8
-
9
- module Sequel
10
- module Railties
11
- module ControllerRuntime
12
- extend ActiveSupport::Concern
3
+ require "active_support/core_ext/module/attr_internal"
4
+ unless defined?(RailsSemanticLogger::Sequel::LogSubscriber)
5
+ require_relative "../../rails_semantic_logger/sequel/log_subscriber"
6
+ end
13
7
 
14
- module ClassMethods
15
- def log_process_action payload
16
- messages = super
17
- db_runtime = payload[:db_runtime]
18
- db_query_count = payload[:db_query_count]
19
- if db_runtime && db_query_count
20
- messages << (format "Sequel: %.1fms & %d queries", db_runtime.to_f, db_query_count)
21
- end
22
- messages
8
+ module Sequel
9
+ module Railties
10
+ module ControllerRuntime
11
+ extend ActiveSupport::Concern
12
+
13
+ module ClassMethods
14
+ def log_process_action payload
15
+ messages = super
16
+ db_runtime = payload[:db_runtime]
17
+ db_query_count = payload[:db_query_count]
18
+ if db_runtime && db_query_count
19
+ messages << (format "Sequel: %.1fms & %d queries", db_runtime.to_f, db_query_count)
23
20
  end
21
+ messages
24
22
  end
23
+ end
25
24
 
26
- private
27
-
28
- attr_internal :db_runtime, :db_query_count
25
+ private
29
26
 
30
- def process_action action, *args
31
- # We also need to reset the runtime before each action
32
- # because of queries in middleware or in cases we are streaming
33
- # and it won't be cleaned up by the method below.
34
- RailsSemanticLogger::Sequel::LogSubscriber.reset_runtime
35
- RailsSemanticLogger::Sequel::LogSubscriber.reset_count
36
- super
37
- end
27
+ attr_internal :db_runtime, :db_query_count
38
28
 
39
- def cleanup_view_runtime
40
- if logger && logger.info?
41
- db_rt_before_render = RailsSemanticLogger::Sequel::LogSubscriber.reset_runtime
42
- self.db_runtime = (db_runtime || 0) + db_rt_before_render
43
- runtime = super
44
- db_rt_after_render = RailsSemanticLogger::Sequel::LogSubscriber.reset_runtime
45
- self.db_runtime += db_rt_after_render
46
- runtime - db_rt_after_render
47
- else
48
- super
49
- end
50
- end
29
+ def process_action action, *args
30
+ # We also need to reset the runtime before each action
31
+ # because of queries in middleware or in cases we are streaming
32
+ # and it won't be cleaned up by the method below.
33
+ RailsSemanticLogger::Sequel::LogSubscriber.reset_runtime
34
+ RailsSemanticLogger::Sequel::LogSubscriber.reset_count
35
+ super
36
+ end
51
37
 
52
- def append_info_to_payload payload
38
+ def cleanup_view_runtime
39
+ if logger && logger.info?
40
+ db_rt_before_render = RailsSemanticLogger::Sequel::LogSubscriber.reset_runtime
41
+ self.db_runtime = (db_runtime || 0) + db_rt_before_render
42
+ runtime = super
43
+ db_rt_after_render = RailsSemanticLogger::Sequel::LogSubscriber.reset_runtime
44
+ self.db_runtime += db_rt_after_render
45
+ runtime - db_rt_after_render
46
+ else
53
47
  super
54
- payload[:db_runtime] =
55
- (db_runtime || 0) + RailsSemanticLogger::Sequel::LogSubscriber.reset_runtime
56
- payload[:db_query_count] =
57
- (db_query_count || 0) + RailsSemanticLogger::Sequel::LogSubscriber.reset_count
58
48
  end
59
49
  end
50
+
51
+ def append_info_to_payload payload
52
+ super
53
+ payload[:db_runtime] =
54
+ (db_runtime || 0) + RailsSemanticLogger::Sequel::LogSubscriber.reset_runtime
55
+ payload[:db_query_count] =
56
+ (db_query_count || 0) + RailsSemanticLogger::Sequel::LogSubscriber.reset_count
57
+ end
60
58
  end
61
59
  end
62
-
63
- ActionController::Base.include Sequel::Railties::ControllerRuntime
64
- ActionController::API.include Sequel::Railties::ControllerRuntime
65
60
  end
61
+
62
+ ActionController::Base.include Sequel::Railties::ControllerRuntime
63
+ ActionController::API.include Sequel::Railties::ControllerRuntime
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic_logger_ecs_addon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sajeev Ramasamy
@@ -34,7 +34,7 @@ cert_chain:
34
34
  vYrYpx2LhW5Xd0nPdr4aI+5BUqGdI7Ypl3BqNHZljUUlieiWu7rU0MhIZgQ1lIMa
35
35
  pQreMxz5itbb+2KmpdBlkm8nuRoFv0jrL5LR+7+UBRknGsHXaEQQcQ==
36
36
  -----END CERTIFICATE-----
37
- date: 2021-11-01 00:00:00.000000000 Z
37
+ date: 2021-11-02 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: request_store
@@ -95,6 +95,7 @@ files:
95
95
  - lib/semantic_logger_ecs_addon/formatters/json.rb
96
96
  - lib/semantic_logger_ecs_addon/formatters/raw.rb
97
97
  - lib/semantic_logger_ecs_addon/identity.rb
98
+ - lib/semantic_logger_ecs_addon/sequel.rb
98
99
  - lib/semantic_logger_ecs_addon/utils/backtrace_cleaner.rb
99
100
  - lib/semantic_logger_ecs_addon/utils/hash.rb
100
101
  - lib/sequel/database.rb
metadata.gz.sig CHANGED
Binary file