activerecord-instrumentation 0.4.0.jlauer1 → 0.4.0.jlauer2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +5 -3
- data/lib/active_record/open_tracing.rb +9 -4
- data/lib/active_record/open_tracing/processor.rb +18 -34
- data/lib/active_record/open_tracing/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64b6684423e203bf4a46392f6c912f934fe568ff7f92ac4341e353dd3374f001
|
4
|
+
data.tar.gz: 2becfd40110f3da47d1ab03bcb80036bd1d1751fda300639ca5614779c575c91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4d38250a120a52b6f68190448b5c3e9961a5cafed4620cea367b98f2ec6e4588c4c35fcd6f369e15b9933d8eed13fe8b018808fe1ce0234aec415966e29a9cb
|
7
|
+
data.tar.gz: 236bf2931c3b2c743698efeb4a1c9cb69b32a0609d12663e5213254680fdf8b68789eb0f42d3f4faabb92467f64641cd94807d29b71db4cf737ecd1d41869163
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Adds OpenTracing instrumentation to ActiveRecord
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'activerecord-
|
10
|
+
gem 'activerecord-instrumentation'
|
11
11
|
```
|
12
12
|
|
13
13
|
## Usage
|
@@ -16,8 +16,10 @@ gem 'activerecord-opentracing'
|
|
16
16
|
require 'opentracing'
|
17
17
|
OpenTracing.global_tracer = TracerImplementation.new
|
18
18
|
|
19
|
-
require 'active_record/
|
20
|
-
|
19
|
+
require 'active_record/open_tracing'
|
20
|
+
# If a sanitizer is specified, it will be used to scrub the sql statements. This is optional.
|
21
|
+
sanitizer = ActiveRecord::OpenTracing::SqlSanitizer.build_sanitizer(:mysql)
|
22
|
+
ActiveRecord::OpenTracing.instrument(sanitizer: sanitizer)
|
21
23
|
```
|
22
24
|
|
23
25
|
# Development
|
@@ -9,15 +9,20 @@ require "active_record/open_tracing/sql_sanitizer"
|
|
9
9
|
|
10
10
|
module ActiveRecord
|
11
11
|
module OpenTracing
|
12
|
-
|
12
|
+
# Instruments activerecord for use with OpenTracing
|
13
|
+
#
|
14
|
+
# @param tracer [OpenTracing::Tracer] The tracer to which to send traces
|
15
|
+
# @param sanitizer [Symbol, String, nil] The sanitizer to use. Options are :mysql,
|
16
|
+
# :postgres, :sql_server, :sqlite. If no sanitizer is specified, or a falsy value
|
17
|
+
# is passed, sql will not be sanitized.
|
18
|
+
# @param sql_logging [Boolean] Whether to log sql statements to the tracer
|
19
|
+
def self.instrument(tracer: ::OpenTracing.global_tracer, sanitizer: nil, sql_logging_enabled: true)
|
13
20
|
sql_sanitizer = sanitizer && SqlSanitizer.build_sanitizer(sanitizer)
|
14
|
-
processor = Processor.new(tracer, sanitizer: sql_sanitizer)
|
21
|
+
processor = Processor.new(tracer, sanitizer: sql_sanitizer, sql_logging_enabled: sql_logging_enabled)
|
15
22
|
|
16
23
|
ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
17
24
|
processor.call(*args)
|
18
25
|
end
|
19
|
-
|
20
|
-
self
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
@@ -8,11 +8,12 @@ module ActiveRecord
|
|
8
8
|
SPAN_KIND = "client"
|
9
9
|
DB_TYPE = "sql"
|
10
10
|
|
11
|
-
attr_reader :tracer, :sanitizer
|
11
|
+
attr_reader :tracer, :sanitizer, :sql_logging_enabled
|
12
12
|
|
13
|
-
def initialize(tracer, sanitizer: nil)
|
13
|
+
def initialize(tracer, sanitizer: nil, sql_logging_enabled: true)
|
14
14
|
@tracer = tracer
|
15
15
|
@sanitizer = sanitizer
|
16
|
+
@sql_logging_enabled = sql_logging_enabled
|
16
17
|
end
|
17
18
|
|
18
19
|
def call(_event_name, start, finish, _id, payload)
|
@@ -48,51 +49,34 @@ module ActiveRecord
|
|
48
49
|
"span.kind" => SPAN_KIND,
|
49
50
|
"db.instance" => db_instance,
|
50
51
|
"db.cached" => payload.fetch(:cached, false),
|
51
|
-
"db.statement" => sanitize_sql(payload.fetch(:sql).squish),
|
52
52
|
"db.type" => DB_TYPE,
|
53
|
-
"peer.address" =>
|
54
|
-
}
|
53
|
+
"peer.address" => peer_address_tag
|
54
|
+
}.merge(db_statement(payload))
|
55
55
|
end
|
56
56
|
|
57
|
-
def
|
58
|
-
|
57
|
+
def db_statement(payload)
|
58
|
+
sql_logging_enabled ? { "db.statement" => sanitize_sql(payload.fetch(:sql).squish) } : {}
|
59
59
|
end
|
60
60
|
|
61
|
-
def
|
62
|
-
|
61
|
+
def sanitize_sql(sql)
|
62
|
+
sanitizer ? sanitizer.sanitize(sql) : sql
|
63
63
|
end
|
64
64
|
|
65
|
-
def
|
66
|
-
@
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
65
|
+
def peer_address_tag
|
66
|
+
@peer_address_tag ||= [
|
67
|
+
"#{connection_config.fetch(:adapter)}://",
|
68
|
+
connection_config[:username],
|
69
|
+
connection_config[:host] && "@#{connection_config[:host]}",
|
70
|
+
"/#{db_instance}"
|
71
71
|
].join
|
72
72
|
end
|
73
73
|
|
74
|
-
def
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
def username_str
|
79
|
-
connection_config[:username]
|
80
|
-
end
|
81
|
-
|
82
|
-
def host_str
|
83
|
-
"@#{connection_config[:host]}" if connection_config[:host]
|
84
|
-
end
|
85
|
-
|
86
|
-
def database_str
|
87
|
-
"/#{connection_config.fetch(:database)}"
|
74
|
+
def db_instance
|
75
|
+
@db_instance ||= connection_config.fetch(:database)
|
88
76
|
end
|
89
77
|
|
90
78
|
def connection_config
|
91
|
-
ActiveRecord::Base.connection_config
|
92
|
-
end
|
93
|
-
|
94
|
-
def db_config
|
95
|
-
@db_config ||= ActiveRecord::Base.connection_config
|
79
|
+
@connection_config ||= ActiveRecord::Base.connection_config
|
96
80
|
end
|
97
81
|
end
|
98
82
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-instrumentation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.0.
|
4
|
+
version: 0.4.0.jlauer2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SaleMove TechMovers
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-04-
|
12
|
+
date: 2020-04-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|