semantic_logger_ecs_addon 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/rails_semantic_logger/sequel/log_subscriber.rb +68 -66
- data/lib/semantic_logger_ecs_addon/identity.rb +1 -1
- data/lib/semantic_logger_ecs_addon.rb +1 -3
- data/lib/sequel/database.rb +35 -0
- data/lib/sequel/railties/controller_runtime.rb +50 -48
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
- data/lib/sequel/database/active_support_notification.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce4015b55b1cb91fd4cb92b6e8e1000a3516128fecf4070988f69dfcbe8cd44a
|
4
|
+
data.tar.gz: '0849c201922f70ad1f7cef19354a648d10b433352f9d3737eb5ac15c3424e651'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6a62ae9c3e5a4971c60d079bd311efa1a0c2f62a2ca3a52d7fe3ee342a4eac0da8f35a6c748af7c0ab51b692656ed96db79917bceea2afd951da3852bc50120
|
7
|
+
data.tar.gz: fe6ce8a9344ed8242fc1bbc0a604df8a94bc1ffe53de6359b9913acba44c990fe4690c30e21282248d4622b6b3c40b2b9bf77086210e768298b1fe9117c54c4a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -1,89 +1,91 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
module
|
5
|
-
|
6
|
-
class
|
7
|
-
|
8
|
-
|
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
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
def self.runtime= value
|
12
|
+
# ::ActiveRecord::RuntimeRegistry.sql_runtime = value
|
13
|
+
RequestStore.store[:sql_runtime] = value
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
def self.runtime
|
17
|
+
# ::ActiveRecord::RuntimeRegistry.sql_runtime ||= 0
|
18
|
+
RequestStore.fetch(:sql_runtime) { 0 }
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def self.count= value
|
22
|
+
RequestStore.store[:sql_count] = value
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def self.count
|
26
|
+
RequestStore.fetch(:sql_count) { 0 }
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
def self.reset_runtime
|
30
|
+
previous = runtime
|
31
|
+
self.runtime = 0
|
32
|
+
previous
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
def self.reset_count
|
36
|
+
previous = count
|
37
|
+
self.count = 0
|
38
|
+
previous
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
def sql event
|
42
|
+
self.class.runtime += event.duration
|
43
|
+
self.class.count += 1
|
44
|
+
return unless logger.debug?
|
44
45
|
|
45
|
-
|
46
|
-
|
46
|
+
payload = event.payload
|
47
|
+
name = payload[:name]
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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]
|
52
53
|
|
53
|
-
|
54
|
+
log = {message: name, payload: log_payload, duration: event.duration}
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
59
60
|
|
60
|
-
|
61
|
-
|
61
|
+
logger.debug log
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
+
private
|
64
65
|
|
65
|
-
|
66
|
+
@logger = SemanticLogger["Sequel"]
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
73
74
|
|
74
|
-
|
75
|
-
|
76
|
-
|
75
|
+
def logger
|
76
|
+
self.class.logger
|
77
|
+
end
|
77
78
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
84
86
|
end
|
85
87
|
end
|
86
88
|
end
|
87
|
-
end
|
88
89
|
|
89
|
-
RailsSemanticLogger::Sequel::LogSubscriber.attach_to :sequel
|
90
|
+
RailsSemanticLogger::Sequel::LogSubscriber.attach_to :sequel
|
91
|
+
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
|
+
VERSION = "0.1.7"
|
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
|
@@ -6,9 +6,7 @@ if defined?(Sequel)
|
|
6
6
|
if defined? ActiveSupport::LogSubscriber
|
7
7
|
require_relative "rails_semantic_logger/sequel/log_subscriber"
|
8
8
|
end
|
9
|
-
if defined?(ActiveSupport::Notifications)
|
10
|
-
require_relative "sequel/database/active_support_notification"
|
11
|
-
end
|
9
|
+
require_relative "sequel/database" if defined?(ActiveSupport::Notifications)
|
12
10
|
require_relative "sequel/railties/controller_runtime" if defined?(ActionController)
|
13
11
|
end
|
14
12
|
|
@@ -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
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
7
8
|
|
8
|
-
module Sequel
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
20
23
|
end
|
21
|
-
messages
|
22
24
|
end
|
23
|
-
end
|
24
25
|
|
25
|
-
|
26
|
+
private
|
26
27
|
|
27
|
-
|
28
|
+
attr_internal :db_runtime, :db_query_count
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
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
|
47
36
|
super
|
48
37
|
end
|
49
|
-
end
|
50
38
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
57
59
|
end
|
58
60
|
end
|
59
61
|
end
|
60
|
-
end
|
61
62
|
|
62
|
-
ActionController::Base.include Sequel::Railties::ControllerRuntime
|
63
|
-
ActionController::API.include Sequel::Railties::ControllerRuntime
|
63
|
+
ActionController::Base.include Sequel::Railties::ControllerRuntime
|
64
|
+
ActionController::API.include Sequel::Railties::ControllerRuntime
|
65
|
+
end
|
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.
|
4
|
+
version: 0.1.7
|
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-08-
|
37
|
+
date: 2021-08-31 00:00:00.000000000 Z
|
38
38
|
dependencies:
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: request_store
|
@@ -97,7 +97,7 @@ files:
|
|
97
97
|
- lib/semantic_logger_ecs_addon/identity.rb
|
98
98
|
- lib/semantic_logger_ecs_addon/utils/backtrace_cleaner.rb
|
99
99
|
- lib/semantic_logger_ecs_addon/utils/hash.rb
|
100
|
-
- lib/sequel/database
|
100
|
+
- lib/sequel/database.rb
|
101
101
|
- lib/sequel/railties/controller_runtime.rb
|
102
102
|
homepage: https://github.com/thorion3006/semantic_logger_ecs_addon
|
103
103
|
licenses:
|
metadata.gz.sig
CHANGED
Binary file
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "sequel/database/logging"
|
4
|
-
require "active_support/notifications"
|
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
|