semantic_logger_ecs_addon 0.1.4 → 0.1.9

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: eadf8edfbe1cf5c37a68f71eebb0d809f0cb9420c1e449902fe7c0a2bfbc0017
4
- data.tar.gz: fbb28cdbcedff8afffeae986ffec6a1df19d6da9c325563388235ea6b81de7f6
3
+ metadata.gz: f53530b3500cfdea92d84066a209c2c3f449b44adea38e425d88bed41424bf3e
4
+ data.tar.gz: b766fb2e188d3e65efe102c32f917f005278220be28ce8110b7a9026d8610356
5
5
  SHA512:
6
- metadata.gz: 1d3dd9fa46fd383916609202e3fa68d405bff42debbbba4cea4e87fe1825707485abc4b94e89cb73a7036fbf9e08cc93be523b16a030f4aa7ee92095b6b4046a
7
- data.tar.gz: 539f0eb6e805d1db8923762fbd96d402b99a005cf7f97cd4cdbe49c571bdedc2c1ee7d8e5b741b8c543b0501256091485609180d3faf6fd4ca424b0827686346
6
+ metadata.gz: 4117727bccc4493029e20622f19ce10c284a39a73d680fdc76f4e6e875734a3d76f8343bf1a90ef77fed2b65b99db19f593fbb98b6bf1dcdee09eb9b5657f66f
7
+ data.tar.gz: 98ae627d2a8793e7b00c30f4da865c81dfef64642402a070cc436ebefbaf9d62ec74973fd6be736e190383d78295efea09adb02ff9ca535e4c8d9dfc33064e92
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,87 +1,91 @@
1
- module RailsSemanticLogger
2
- module Sequel
3
- class LogSubscriber < ActiveSupport::LogSubscriber
4
- class << self
5
- attr_reader :logger
6
- end
7
-
8
- def self.runtime= value
9
- # ::ActiveRecord::RuntimeRegistry.sql_runtime = value
10
- RequestStore.store[:sql_runtime] = value
11
- end
12
-
13
- def self.runtime
14
- # ::ActiveRecord::RuntimeRegistry.sql_runtime ||= 0
15
- RequestStore.fetch(:sql_runtime) { 0 }
16
- end
17
-
18
- def self.count= value
19
- RequestStore.store[:sql_count] = value
20
- end
21
-
22
- def self.count
23
- RequestStore.fetch(:sql_count) { 0 }
24
- end
25
-
26
- def self.reset_runtime
27
- previous = runtime
28
- self.runtime = 0
29
- previous
30
- end
31
-
32
- def self.reset_count
33
- previous = count
34
- self.count = 0
35
- previous
36
- end
37
-
38
- def sql event
39
- self.class.runtime += event.duration
40
- self.class.count += 1
41
- return unless logger.debug?
42
-
43
- payload = event.payload
44
- name = payload[:name]
45
-
46
- log_payload = {sql: payload[:sql].squeeze(" ")}
47
- log_payload[:binds] = bind_values payload unless (payload[:binds] || []).empty?
48
- log_payload[:allocations] = event.allocations if event.respond_to? :allocations
49
- log_payload[:cached] = event.payload[:cached]
50
-
51
- log = {message: name, payload: log_payload, duration: event.duration}
52
-
53
- # Log the location of the query itself.
54
- if logger.send(:level_index) >= SemanticLogger.backtrace_level_index
55
- log[:backtrace] = SemanticLogger::Utils.strip_backtrace caller
56
- end
57
-
58
- logger.debug log
59
- end
60
-
61
- private
62
-
63
- @logger = SemanticLogger["Sequel"]
64
-
65
- # When multiple values are received for a single bound field, it is converted into an array
66
- def add_bind_value binds, key, value
67
- key = key.downcase.to_sym unless key.nil?
68
- value = (Array(binds[key]) << value) if binds.key? key
69
- binds[key] = value
70
- end
71
-
72
- def logger
73
- self.class.logger
74
- end
75
-
76
- def bind_values payload
77
- binds = {}
78
- binds = " " + payload[:binds].map { |col, v| [col.name, v] }
79
- .inspect
80
- payload[:binds].each { |col, value| add_bind_value binds, col.name, value }
81
- binds
82
- end
83
- end
84
- end
85
- end
86
-
87
- RailsSemanticLogger::Sequel::LogSubscriber.attach_to :sequel
1
+ # # frozen_string_literal: true
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
15
+
16
+ # def self.runtime
17
+ # # ::ActiveRecord::RuntimeRegistry.sql_runtime ||= 0
18
+ # RequestStore.fetch(:sql_runtime) { 0 }
19
+ # end
20
+
21
+ # def self.count= value
22
+ # RequestStore.store[:sql_count] = value
23
+ # end
24
+
25
+ # def self.count
26
+ # RequestStore.fetch(:sql_count) { 0 }
27
+ # end
28
+
29
+ # def self.reset_runtime
30
+ # previous = runtime
31
+ # self.runtime = 0
32
+ # previous
33
+ # end
34
+
35
+ # def self.reset_count
36
+ # previous = count
37
+ # self.count = 0
38
+ # previous
39
+ # end
40
+
41
+ # def sql event
42
+ # self.class.runtime += event.duration
43
+ # self.class.count += 1
44
+ # return unless logger.debug?
45
+
46
+ # payload = event.payload
47
+ # name = payload[:name]
48
+
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]
53
+
54
+ # log = {message: name, payload: log_payload, duration: event.duration}
55
+
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
60
+
61
+ # logger.debug log
62
+ # end
63
+
64
+ # private
65
+
66
+ # @logger = SemanticLogger["Sequel"]
67
+
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
74
+
75
+ # def logger
76
+ # self.class.logger
77
+ # end
78
+
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
86
+ # end
87
+ # end
88
+ # end
89
+
90
+ # RailsSemanticLogger::Sequel::LogSubscriber.attach_to :sequel
91
+ # end
@@ -5,8 +5,8 @@ module SemanticLoggerEcsAddon
5
5
  module Identity
6
6
  NAME = "semantic_logger_ecs_addon"
7
7
  LABEL = "Semantic Logger Ecs Addon"
8
- VERSION = "0.1.4"
8
+ VERSION = "0.1.9"
9
9
  VERSION_LABEL = "#{LABEL} #{VERSION}"
10
- SUMMARY = "A semantic logger formatter that formats the logs according to Elastic Common Schema and adds APM trace data if ElasticAPM is enabled."
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
12
12
  end
@@ -2,13 +2,13 @@
2
2
 
3
3
  require "pathname"
4
4
  require "zeitwerk"
5
- if defined? ActiveSupport::LogSubscriber
6
- require_relative "rails_semantic_logger/sequel/log_subscriber"
7
- end
8
- if defined?(ActiveSupport::Notifications)
9
- require_relative "sequel/database/active_support_notification"
10
- end
11
- require_relative "sequel/railties/controller_runtime" if defined?(ActionController)
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
12
 
13
13
  loader = Zeitwerk::Loader.for_gem
14
14
  loader.setup
@@ -0,0 +1,35 @@
1
+ # # frozen_string_literal: true
2
+
3
+ # if defined?(Sequel) && defined?(ActiveSupport::Notifications)
4
+ # require "sequel/database/logging"
5
+
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?
27
+ # end
28
+ # end
29
+
30
+ # def log_yield sql, args = nil, &block
31
+ # log_connection_yield(sql, nil, args, &block)
32
+ # end
33
+ # end
34
+ # end
35
+ # end
@@ -1,63 +1,65 @@
1
- # frozen_string_literal: true
2
-
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
7
-
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)
20
- end
21
- messages
22
- end
23
- end
24
-
25
- private
26
-
27
- attr_internal :db_runtime, :db_query_count
28
-
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
37
-
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
47
- super
48
- end
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
58
- end
59
- end
60
- end
61
-
62
- ActionController::Base.include Sequel::Railties::ControllerRuntime
63
- ActionController::API.include Sequel::Railties::ControllerRuntime
1
+ # # frozen_string_literal: true
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
13
+
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
23
+ # end
24
+ # end
25
+
26
+ # private
27
+
28
+ # attr_internal :db_runtime, :db_query_count
29
+
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
38
+
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
51
+
52
+ # def append_info_to_payload payload
53
+ # 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
+ # end
59
+ # end
60
+ # end
61
+ # end
62
+
63
+ # ActionController::Base.include Sequel::Railties::ControllerRuntime
64
+ # ActionController::API.include Sequel::Railties::ControllerRuntime
65
+ # end
data.tar.gz.sig CHANGED
@@ -1,2 +1 @@
1
- =lT����!ܴ=-Q��� �R�����K�����n]�@����sJ0����KKL��g�NfM�|G���N
2
- mW�S�����%͂����u�8Ɏ7�`��y�V�S��ݠV���"粅�8�H/��'�n6��K*�7��i#پ��)�ܓe������s/٫��{`H5�/
1
+ .������(��Sk�*ݺ|N˔�umۈD��~˂�m�K��.������3Xu$qyI.�gn(?���i���Y�CP|?��#{�kI�F�������3i�o`KA0��P�����;����9�r��s1'7:ێ�sje�80R�כ���e\0�o��&^�5��T!�d��6�I�'U�����mq�1ٶ׻���Y���ߵW���K5���뒣2h�z�L�-�[sn�o'��ؼ8t��� ������J{�<���K��[�u��Tns��D���:U ��[Jd�'-��Y�}��G �=�`�в0}@����%9�����G�*͎!���-9-��S�Q<xN��Å����z*A���6�u�CXx�>�
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.4
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sajeev Ramasamy
@@ -34,8 +34,22 @@ cert_chain:
34
34
  vYrYpx2LhW5Xd0nPdr4aI+5BUqGdI7Ypl3BqNHZljUUlieiWu7rU0MhIZgQ1lIMa
35
35
  pQreMxz5itbb+2KmpdBlkm8nuRoFv0jrL5LR+7+UBRknGsHXaEQQcQ==
36
36
  -----END CERTIFICATE-----
37
- date: 2021-08-23 00:00:00.000000000 Z
37
+ date: 2021-11-01 00:00:00.000000000 Z
38
38
  dependencies:
39
+ - !ruby/object:Gem::Dependency
40
+ name: request_store
41
+ requirement: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - "~>"
44
+ - !ruby/object:Gem::Version
45
+ version: '1.5'
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.5'
39
53
  - !ruby/object:Gem::Dependency
40
54
  name: semantic_logger
41
55
  requirement: !ruby/object:Gem::Requirement
@@ -83,7 +97,7 @@ files:
83
97
  - lib/semantic_logger_ecs_addon/identity.rb
84
98
  - lib/semantic_logger_ecs_addon/utils/backtrace_cleaner.rb
85
99
  - lib/semantic_logger_ecs_addon/utils/hash.rb
86
- - lib/sequel/database/active_support_notification.rb
100
+ - lib/sequel/database.rb
87
101
  - lib/sequel/railties/controller_runtime.rb
88
102
  homepage: https://github.com/thorion3006/semantic_logger_ecs_addon
89
103
  licenses:
@@ -115,5 +129,6 @@ rubygems_version: 3.2.22
115
129
  signing_key:
116
130
  specification_version: 4
117
131
  summary: A semantic logger formatter that formats the logs according to Elastic Common
118
- Schema and adds APM trace data if ElasticAPM is enabled.
132
+ Schema, adds APM trace data if ElasticAPM is enabled and instruments sequel logs
133
+ for rails if available.
119
134
  test_files: []
metadata.gz.sig CHANGED
Binary file
@@ -1,32 +0,0 @@
1
- require "sequel/database/logging"
2
- # require "active_support/notifications"
3
-
4
- module Sequel
5
- class Database
6
- def log_connection_yield sql, conn, args = nil
7
- log_connection_info = (connection_info conn if conn && log_connection_info)
8
- log_args = ("; #{args.inspect}" if args)
9
- sql_for_log = "#{log_connection_info}#{sql}#{log_args}"
10
- start = Time.now
11
- begin
12
- ::ActiveSupport::Notifications.instrument(
13
- "sql.sequel",
14
- sql: sql,
15
- name: self.class,
16
- binds: args
17
- ) do
18
- yield
19
- end
20
- rescue StandardError => error
21
- log_exception error, sql_for_log unless @loggers.empty?
22
- raise
23
- ensure
24
- log_duration Time.now - start, sql_for_log unless error || @loggers.empty?
25
- end
26
- end
27
-
28
- def log_yield sql, args = nil, &block
29
- log_connection_yield(sql, nil, args, &block)
30
- end
31
- end
32
- end