semantic_logger_ecs_addon 0.1.0 → 0.1.7

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: 9d56d0ab9e926ca66fd4889271eb4b5157b41b2b6719b6fc22ebf2acd29745eb
4
- data.tar.gz: 518de9e56bd832649fdf2cda28da0a0453461bafa2895ac9cf4169058625d817
3
+ metadata.gz: ce4015b55b1cb91fd4cb92b6e8e1000a3516128fecf4070988f69dfcbe8cd44a
4
+ data.tar.gz: '0849c201922f70ad1f7cef19354a648d10b433352f9d3737eb5ac15c3424e651'
5
5
  SHA512:
6
- metadata.gz: ca8f68e438c4f018e1205b513455120f8b8cefbe311b980614e4a7f739672391362b58203d99696b4d51a21e80f726488ffcb6d03893ec277822fd0caa00e47a
7
- data.tar.gz: 30f219878394f83e632e222241a23323cb090323faafe86a0dccb0d430ad7cc4cea95cd942db3070e892b5765f911f6bd4f53893b66a64b992fd97124420f1a4
6
+ metadata.gz: a6a62ae9c3e5a4971c60d079bd311efa1a0c2f62a2ca3a52d7fe3ee342a4eac0da8f35a6c748af7c0ab51b692656ed96db79917bceea2afd951da3852bc50120
7
+ data.tar.gz: fe6ce8a9344ed8242fc1bbc0a604df8a94bc1ffe53de6359b9913acba44c990fe4690c30e21282248d4622b6b3c40b2b9bf77086210e768298b1fe9117c54c4a
checksums.yaml.gz.sig CHANGED
Binary file
data/LICENSE.md CHANGED
File without changes
data/README.md CHANGED
File without changes
@@ -0,0 +1,91 @@
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
@@ -145,7 +145,9 @@ module SemanticLoggerEcsAddon
145
145
  end
146
146
 
147
147
  def rack_metrics
148
- metrics_keys = formatted_payload.keys.select { |k| k.to_s.end_with?("_runtime") }
148
+ metrics_keys = formatted_payload.keys.select do |k|
149
+ k.to_s.end_with? "_runtime", "_count"
150
+ end
149
151
  formatted_payload[:metrics].merge! formatted_payload.extract!(:allocations, *metrics_keys)
150
152
  formatted_payload[:metrics][:object_allocations] =
151
153
  formatted_payload[:metrics].delete :allocations
@@ -162,11 +164,13 @@ module SemanticLoggerEcsAddon
162
164
  end
163
165
 
164
166
  def format_payload
165
- return unless log.payload.respond_to?(:empty?) && !log.payload.empty?
166
-
167
- self.formatted_payload = Utils::Hash[**log.payload]
167
+ if log.payload.respond_to?(:empty?) && !log.payload.empty?
168
+ self.formatted_payload = Utils::Hash[**log.payload]
168
169
 
169
- rack_extract
170
+ rack_extract
171
+ else
172
+ self.formatted_payload = {}
173
+ end
170
174
  end
171
175
 
172
176
  def request
File without changes
File without changes
@@ -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.0"
8
+ VERSION = "0.1.7"
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
File without changes
@@ -2,6 +2,13 @@
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
5
12
 
6
13
  loader = Zeitwerk::Loader.for_gem
7
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
@@ -0,0 +1,65 @@
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 +1,4 @@
1
- ��=3�D�od��q&|}!������UE��d��"��0��}�J�ۮNg����{�P��GL���"���C<aB�{X����:��V�n`���g>�������O�'�\�H�`�O���$����Gi�<�;�8�-�m&�B9�`.+�p BNl�,�&���\��*���WfvI%���\����k�D愕ւod���@�B�P
1
+ <P�,JtI����=�#�@P������ڄ_P] uc�D��G��X��;eq`�t��۝HuawqKW�� �,��Fv6U�ۛ�n�;8�x
2
+ E"x��q��T�z��5 ���I]B:J�H�p��;]�%���DG1��gޗ`3|��I����t�m&7�]XH���T��pq:r�#��8�R"S��<��A���zn}[��W�*���!���$&�scyһm q�vWݨ�͋Ψ|�@n��Rm,.��
3
+ gG�B���O�F"�cn��+sɼ3u\`2A�`KÀ&P�4�.R�
4
+ � �]|㹨�y��}��D��}�=�9���R:#��)�O�����yc-lN��yA�ϑ��a��
metadata CHANGED
@@ -1,41 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic_logger_ecs_addon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sajeev Ramasamy
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIERDCCAqygAwIBAgIBATANBgkqhkiG9w0BAQsFADAmMSQwIgYDVQQDDBt0aG9y
14
- aW9uMzAwNi9EQz1nbWFpbC9EQz1jb20wHhcNMjEwNjA4MTAyMzI4WhcNMjIwNjA4
15
- MTAyMzI4WjAmMSQwIgYDVQQDDBt0aG9yaW9uMzAwNi9EQz1nbWFpbC9EQz1jb20w
16
- ggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQC1entXzzkGYW4W906xYuTr
17
- 6SQWJXxjPo3GrsWk2L+KXMkY94d1MyJN9IJ0LEy6M7onkmpYSzFqBQ8W+8VRaW0y
18
- HVLX1EQRZ9hVd0LV9j5tNx2pDUfXzoxeyNllBd64Ne7r/6D93lAErATC/+v9X6QC
19
- cHd17QBGWU8Qb0ePkYY1UvImbePdgLRwu6F2KrUPyn3ewoAvBxsAG74XU6SbORQ2
20
- 7Hhfh9vvRAcgboXmbyPW+6Z6KN7YdBFnAwI7r/9M9cMRhWwpprTPwKNdAMR0wl+l
21
- Bdp7Se7x8fxriTl9TTpgMScGdXIc/m2Pj48W+cnk5Wf2xlcrzXptX3UYelF8f7j3
22
- R/Ft2OTSvG0jdYW50mGD96Om0WKM6Ggfx0Dz6pvComl2LNajTSYpHB0xj8d1L6QX
23
- UQ2kcIERhnVMqriZauA21b2J9ZLxFf+Ddou7V2AiLMlFi9cPxgj4eHrHLiOylC29
24
- sBztOdq1mbfofNe5ifothYpj/uMKYEdXRjlKXUITCFcCAwEAAaN9MHswCQYDVR0T
25
- BAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFP9FcvZBAdqH9D6ECTtDk6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ATE-----
37
- date: 2021-06-27 00:00:00.000000000 Z
37
+ date: 2021-08-31 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
@@ -64,7 +78,7 @@ dependencies:
64
78
  - - "~>"
65
79
  - !ruby/object:Gem::Version
66
80
  version: '2.4'
67
- description:
81
+ description:
68
82
  email:
69
83
  - thorion3006@gmail.com
70
84
  executables: []
@@ -75,6 +89,7 @@ extra_rdoc_files:
75
89
  files:
76
90
  - LICENSE.md
77
91
  - README.md
92
+ - lib/rails_semantic_logger/sequel/log_subscriber.rb
78
93
  - lib/semantic_logger_ecs_addon.rb
79
94
  - lib/semantic_logger_ecs_addon/formatters/base.rb
80
95
  - lib/semantic_logger_ecs_addon/formatters/json.rb
@@ -82,6 +97,8 @@ files:
82
97
  - lib/semantic_logger_ecs_addon/identity.rb
83
98
  - lib/semantic_logger_ecs_addon/utils/backtrace_cleaner.rb
84
99
  - lib/semantic_logger_ecs_addon/utils/hash.rb
100
+ - lib/sequel/database.rb
101
+ - lib/sequel/railties/controller_runtime.rb
85
102
  homepage: https://github.com/thorion3006/semantic_logger_ecs_addon
86
103
  licenses:
87
104
  - MIT
@@ -90,7 +107,7 @@ metadata:
90
107
  changelog_uri: https://github.com/thorion3006/semantic_logger_ecs_addon/blob/master/CHANGES.md
91
108
  documentation_uri: https://github.com/thorion3006/semantic_logger_ecs_addon
92
109
  source_code_uri: https://github.com/thorion3006/semantic_logger_ecs_addon
93
- post_install_message:
110
+ post_install_message:
94
111
  rdoc_options: []
95
112
  require_paths:
96
113
  - lib
@@ -108,9 +125,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
125
  - !ruby/object:Gem::Version
109
126
  version: '0'
110
127
  requirements: []
111
- rubygems_version: 3.2.15
112
- signing_key:
128
+ rubygems_version: 3.2.22
129
+ signing_key:
113
130
  specification_version: 4
114
131
  summary: A semantic logger formatter that formats the logs according to Elastic Common
115
- 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.
116
134
  test_files: []
metadata.gz.sig CHANGED
Binary file