semantic_logger_ecs_addon 0.1.1 → 0.1.4

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: c737f17a901802f4dc4489f49060bc1905d29bac92978d044ed819325b470589
4
- data.tar.gz: 87d0e96cddceefaa89f3fdcf98e33be743c74d4513bbbdd2f07dd76cd6b85ce0
3
+ metadata.gz: eadf8edfbe1cf5c37a68f71eebb0d809f0cb9420c1e449902fe7c0a2bfbc0017
4
+ data.tar.gz: fbb28cdbcedff8afffeae986ffec6a1df19d6da9c325563388235ea6b81de7f6
5
5
  SHA512:
6
- metadata.gz: c0492a1e95e2d56ff67313adbab5c06de1e6a27468f17fc5c688d8993fe5fa645dbdf2282f89fd7297c8d9b6581bb125129284c3e48dc02bcfc1e2a52a4cc92a
7
- data.tar.gz: 4e72ea15867334218bda97eda2f74025ff522226d41bec7fd366c455e2fc5d0a9c050be2a909ee6ce68d257a8301397f668c91704b1e757ea13d40ca4ace36d8
6
+ metadata.gz: 1d3dd9fa46fd383916609202e3fa68d405bff42debbbba4cea4e87fe1825707485abc4b94e89cb73a7036fbf9e08cc93be523b16a030f4aa7ee92095b6b4046a
7
+ data.tar.gz: 539f0eb6e805d1db8923762fbd96d402b99a005cf7f97cd4cdbe49c571bdedc2c1ee7d8e5b741b8c543b0501256091485609180d3faf6fd4ca424b0827686346
checksums.yaml.gz.sig CHANGED
@@ -1 +1,3 @@
1
- /}�)5|�On�RF5�6��������^�Z�P�[W{C�0m4����j���V�#-��p�$�]X�O����P�Y]�n��J����c�����42�`�i�{�c�jA�����p*�ֽ6i�%��7:��э#�?�xn�ڽ�wU�j������j�{)X�-/��:�)OF'PA�6Y�?0��%l�z�4�]�}V(����!��88~[��e�z꺺�����IA�VN�Y�'��8`��b��L=��2-�t����1�3W�
1
+ 3]��@
2
+ Q��~��#`C�m�G�ލ
3
+ �K����#� �� �Foԟ��kz��.��F*8��"�}�ӎ[V�.�6�\*i���5��
data/LICENSE.md CHANGED
File without changes
data/README.md CHANGED
File without changes
@@ -0,0 +1,87 @@
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
@@ -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
File without changes
File without changes
@@ -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.1"
8
+ VERSION = "0.1.4"
9
9
  VERSION_LABEL = "#{LABEL} #{VERSION}"
10
10
  SUMMARY = "A semantic logger formatter that formats the logs according to Elastic Common Schema and adds APM trace data if ElasticAPM is enabled."
11
11
  end
File without changes
@@ -2,6 +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
12
 
6
13
  loader = Zeitwerk::Loader.for_gem
7
14
  loader.setup
@@ -0,0 +1,32 @@
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
@@ -0,0 +1,63 @@
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
data.tar.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- 4K�#�
2
- o��1���i} ����
1
+ =lT����!ܴ=-Q��� �R�����K�����n�]�@����s�J0����KKL��g�NfM�|G���N�
2
+ mW�S�����%͂����u�8Ɏ7�`��y�V�S��ݠV���"粅�8�H/��'�n6��K*�7��i#پ��)�ܓe������s/٫��{`H5�/
metadata CHANGED
@@ -1,40 +1,40 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic_logger_ecs_addon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.4
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
-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NkBnbWFpbC5jb20wDQYJKoZIhvcNAQELBQADggGBALGLP4+FXfd1
28
+ 7+1Tlrd477uRIBjbGg7D/7g04xYVNjOMNGI7gUHbi1rlQ6TDg72EBefcnfsBe/IC
29
+ Wr5NxA/nhZl8ulMIWkypyk6tgq4wMe9I8umE83A8960vG6GSf12AuAfdZ5pQGz0V
30
+ tKGUKqED9Yzsmayw+DZgUi1KSezmGdz2Y3BW6DBrNx8qHXUjgPwDnyzdPHTOPqly
31
+ dxZBuseVz7147l9amCG1fopHUpEkPSYznbOaKPyLCdSxfaKu9dwZQ1uF9DTIKGg6
32
+ 16+iw7FZcVbyjw1KQTkYxPOaQcxwNCKQ+yVeICli6NoOinyzO4+onRG8fLOyREaW
33
+ NGxVhaV01YqK1z7lZZoAuVWqbE1NMIO//5tvWC9slgKmWyuCc5YQCT3w+3sA4y82
34
+ vYrYpx2LhW5Xd0nPdr4aI+5BUqGdI7Ypl3BqNHZljUUlieiWu7rU0MhIZgQ1lIMa
35
+ pQreMxz5itbb+2KmpdBlkm8nuRoFv0jrL5LR+7+UBRknGsHXaEQQcQ==
36
36
  -----END CERTIFICATE-----
37
- date: 2021-06-28 00:00:00.000000000 Z
37
+ date: 2021-08-23 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: semantic_logger
@@ -64,7 +64,7 @@ dependencies:
64
64
  - - "~>"
65
65
  - !ruby/object:Gem::Version
66
66
  version: '2.4'
67
- description:
67
+ description:
68
68
  email:
69
69
  - thorion3006@gmail.com
70
70
  executables: []
@@ -75,6 +75,7 @@ extra_rdoc_files:
75
75
  files:
76
76
  - LICENSE.md
77
77
  - README.md
78
+ - lib/rails_semantic_logger/sequel/log_subscriber.rb
78
79
  - lib/semantic_logger_ecs_addon.rb
79
80
  - lib/semantic_logger_ecs_addon/formatters/base.rb
80
81
  - lib/semantic_logger_ecs_addon/formatters/json.rb
@@ -82,6 +83,8 @@ files:
82
83
  - lib/semantic_logger_ecs_addon/identity.rb
83
84
  - lib/semantic_logger_ecs_addon/utils/backtrace_cleaner.rb
84
85
  - lib/semantic_logger_ecs_addon/utils/hash.rb
86
+ - lib/sequel/database/active_support_notification.rb
87
+ - lib/sequel/railties/controller_runtime.rb
85
88
  homepage: https://github.com/thorion3006/semantic_logger_ecs_addon
86
89
  licenses:
87
90
  - MIT
@@ -90,7 +93,7 @@ metadata:
90
93
  changelog_uri: https://github.com/thorion3006/semantic_logger_ecs_addon/blob/master/CHANGES.md
91
94
  documentation_uri: https://github.com/thorion3006/semantic_logger_ecs_addon
92
95
  source_code_uri: https://github.com/thorion3006/semantic_logger_ecs_addon
93
- post_install_message:
96
+ post_install_message:
94
97
  rdoc_options: []
95
98
  require_paths:
96
99
  - lib
@@ -108,8 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
111
  - !ruby/object:Gem::Version
109
112
  version: '0'
110
113
  requirements: []
111
- rubygems_version: 3.2.15
112
- signing_key:
114
+ rubygems_version: 3.2.22
115
+ signing_key:
113
116
  specification_version: 4
114
117
  summary: A semantic logger formatter that formats the logs according to Elastic Common
115
118
  Schema and adds APM trace data if ElasticAPM is enabled.
metadata.gz.sig CHANGED
Binary file