activerecord-instrumentation 0.6.0.jhemphill3 → 0.6.0.jhemphill4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/Gemfile.lock +1 -1
- data/lib/active_record/open_tracing/processor.rb +27 -13
- data/lib/active_record/open_tracing/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fceef2796a103f493c939152dcdaa4428111c082e3908354abfbe04b1614f16
|
4
|
+
data.tar.gz: ef23a8d9a4fe682d7dfd5c6d23b8bb45fd188917240d79b27fa1417c56522c90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70d78da8a4bb59a1f917d94b65bc5c7cdb75a16de16220727ef21ae4c03cf0ba7fa7d12a8d4a266af693cc4971c91b78e8327550f0cc254b169c1da76446b012
|
7
|
+
data.tar.gz: 33b0aa8435da2e6aa7d9877d1019feb37d9d984a39a2906d6dfd614fc26f75afdb53d1bad0782a558e3d8472b621be76abca53c2fc4df87a2fa7c3a27a8060ee
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -73,6 +73,8 @@ module ActiveRecord
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def tags_for_payload(payload)
|
76
|
+
db_config = connection_config(payload[:connection])
|
77
|
+
|
76
78
|
{
|
77
79
|
"component" => COMPONENT_NAME,
|
78
80
|
"span.kind" => SPAN_KIND,
|
@@ -80,7 +82,7 @@ module ActiveRecord
|
|
80
82
|
"db.cached" => payload.fetch(:cached, false),
|
81
83
|
"db.type" => DB_TYPE,
|
82
84
|
"peer.mysql_db_name" => mysql_db_name_tag(payload.fetch(:connection, nil)&.raw_connection),
|
83
|
-
"peer.address" => peer_address_tag
|
85
|
+
"peer.address" => peer_address_tag(db_config)
|
84
86
|
}.merge(db_statement(payload))
|
85
87
|
end
|
86
88
|
|
@@ -110,24 +112,36 @@ module ActiveRecord
|
|
110
112
|
return nil
|
111
113
|
end
|
112
114
|
|
113
|
-
def peer_address_tag
|
114
|
-
@peer_address_tag ||=
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
].join
|
115
|
+
def peer_address_tag(config)
|
116
|
+
@peer_address_tag ||= [
|
117
|
+
"#{config.fetch(:adapter)}://",
|
118
|
+
config[:username],
|
119
|
+
config[:host] && "@#{config[:host]}",
|
120
|
+
"/#{db_instance}"
|
121
|
+
].join
|
121
122
|
end
|
122
123
|
|
123
124
|
def db_instance
|
124
125
|
@db_instance ||= connection_config.fetch(:database)
|
125
126
|
end
|
126
127
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
128
|
+
# If a connection is passed in, pull the db config options hash from it. This connection
|
129
|
+
# is likely to be attached to the query/query client. Fall back to the application level
|
130
|
+
# config. This change will show writer vs reader/replica dbs in spans when it is determined
|
131
|
+
# at the query level.
|
132
|
+
def connection_config(connection = nil)
|
133
|
+
unless defined? @connection_config
|
134
|
+
if connection.raw_connection && connection.raw_connection.respond_to?(:query_options)
|
135
|
+
# you have a mysql client
|
136
|
+
@connection_config = connection.raw_connection.query_options
|
137
|
+
else
|
138
|
+
# Rails 6.2 will deprecate ActiveRecord::Base.connection_config
|
139
|
+
@connection_config = ActiveRecord::Base.try(:connection_db_config)&.configuration_hash ||
|
140
|
+
ActiveRecord::Base.connection_config
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
@connection_config
|
131
145
|
end
|
132
146
|
end
|
133
147
|
end
|