oneapm_rpm 1.2.9 → 1.3.0.rc1
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
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzJkZmRlMGY5MmE5ZWM1MzBiMWQzOGI4OTU2MzM5OTEzYmU2OTE2NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTE2ZWUwMGRhZDg5ZjdhZjNjNzlkY2UzYmUxYjBkNjQyODEwOTY0OQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzMyNDAzNDliNmYwZTdhNDI4OTNmMDUxN2UyNWRmOWMxZWU5OTUwOWFjMWJk
|
10
|
+
N2IxYTIzN2ZiNDg4ODU5OGJkZjIyMmY4NzdkYWNmZjVkMDRkMzBiNzgwMGVk
|
11
|
+
YjQ0MDA1NDVmY2U1ZTIyZDUyNmQ4YWQ1NGQ4YTc0Mjc5Y2Q0ZDU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmYwZGJhZTQxODk0Yzc1ZDUzZWE1NDM5Y2I2YTI3MzBjOTU1ZjE4OTc5NDFh
|
14
|
+
YzVjYzMwZmVkODgyMGE4NWU2MWM2ZjU2M2U5YjBkMjVjNjYzZTQ1ZTY4YmI3
|
15
|
+
YjJlMzQ0ZTNmZTgxZWUyNGM0MDc2OGJjNjg1OTY3NTBmZjI1YzY=
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'one_apm/agent/datastore/mongo/obfuscator'
|
4
|
+
|
5
|
+
module OneApm
|
6
|
+
module Agent
|
7
|
+
module Datastore
|
8
|
+
module Mongo
|
9
|
+
module CommandFormatter
|
10
|
+
|
11
|
+
OBFUSCATE_KEYS = [ 'filter', 'query', ].freeze
|
12
|
+
BLACKLISTED_KEYS = [ 'deletes', 'documents', 'updates' ].freeze
|
13
|
+
OBFUSCATE_NOSQL_KEYS = [ 'filter', 'query', 'deletes', 'documents', 'updates' ].freeze
|
14
|
+
|
15
|
+
|
16
|
+
def self.format(event, status)
|
17
|
+
return nil unless OneApm::Manager.config[:'mongo.capture_queries']
|
18
|
+
result = {
|
19
|
+
:operation => event.command_name,
|
20
|
+
:database => event.database_name,
|
21
|
+
:collection => event.command.values.first,
|
22
|
+
:command => event.command,
|
23
|
+
:status => status
|
24
|
+
}
|
25
|
+
|
26
|
+
event.command.each do |key, value|
|
27
|
+
next if BLACKLISTED_KEYS.include?(key)
|
28
|
+
if OBFUSCATE_KEYS.include?(key)
|
29
|
+
obfuscated = obfuscate(value)
|
30
|
+
result[key] = obfuscated if obfuscated
|
31
|
+
else
|
32
|
+
result[key] = value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
result
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.format_sql(event, status)
|
39
|
+
return nil unless OneApm::Manager.config[:'mongo.capture_queries']
|
40
|
+
header = "db.#{event.command.values.first}.#{event.command_name}"
|
41
|
+
obfuscate_sql = []
|
42
|
+
event.command.each do |key, value|
|
43
|
+
if OBFUSCATE_NOSQL_KEYS.include?(key)
|
44
|
+
if value.is_a?(Array)
|
45
|
+
value.each do |val|
|
46
|
+
obfuscate_sql << "(#{obfuscate_json(val)})"
|
47
|
+
end
|
48
|
+
else
|
49
|
+
obfuscate_sql << "(#{obfuscate_json(value)})"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
header.concat(obfuscate_sql.join(", "))
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.obfuscate_json value
|
57
|
+
obfuscate_value = obfuscate(value)
|
58
|
+
obfuscate_value.to_s.gsub('=>', ':').gsub('"', '') if obfuscate_value
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.obfuscate(statement)
|
62
|
+
statement = Obfuscator.obfuscate_statement(statement) if OneApm::Manager.config[:'mongo.obfuscate_queries']
|
63
|
+
statement
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -11,6 +11,10 @@ module OneApm
|
|
11
11
|
!is_version2?
|
12
12
|
end
|
13
13
|
|
14
|
+
def self.is_support_version2?
|
15
|
+
defined?(::Mongo::Monitoring) && is_version2?
|
16
|
+
end
|
17
|
+
|
14
18
|
# At present we explicitly don't support version 2.x of the driver yet
|
15
19
|
def self.is_version2?
|
16
20
|
defined?(::Mongo::VERSION) &&
|
@@ -1,87 +1,116 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
def hook_instrument_method_for_collection
|
24
|
-
methods = [:create,:drop, :find, :indexes, :insert_one, :insert_many, :bulk_write, :parallel_scan]
|
25
|
-
instrument_methods_with_oneapm(::Mongo::Collection, methods)
|
26
|
-
end
|
3
|
+
module OneApm
|
4
|
+
module Agent
|
5
|
+
module Instrumentation
|
6
|
+
class MongoCommandSubscriber
|
7
|
+
|
8
|
+
MONGODB = 'MongoDB'.freeze
|
9
|
+
STARTED = 'STARTED'.freeze
|
10
|
+
SUCCEEDED = 'SUCCEEDED'.freeze
|
11
|
+
FAILED = 'FAILED'.freeze
|
12
|
+
|
13
|
+
def started(event)
|
14
|
+
begin
|
15
|
+
return unless OneApm::Manager.tl_is_execution_traced?
|
16
|
+
operations[event.operation_id] = event
|
17
|
+
rescue Exception => e
|
18
|
+
log_operations_error(STARTED, e)
|
19
|
+
end
|
20
|
+
end
|
27
21
|
|
22
|
+
def succeeded(event)
|
23
|
+
operator SUCCEEDED, event
|
24
|
+
end
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
instrument_methods_with_oneapm(::Mongo::Collection::View, methods)
|
33
|
-
end
|
26
|
+
def failed(event)
|
27
|
+
operator FAILED, event
|
28
|
+
end
|
34
29
|
|
30
|
+
private
|
35
31
|
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
def operations
|
33
|
+
@operations ||= {}
|
34
|
+
end
|
39
35
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
36
|
+
def mertircs(event)
|
37
|
+
OneApm::Agent::Datastore::MetricHelper.metrics_for(
|
38
|
+
MONGODB, event.command_name, event.command.values.first
|
39
|
+
)
|
40
|
+
end
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
42
|
+
def operator(operator_type, event)
|
43
|
+
begin
|
44
|
+
state = OneApm::TransactionState.tl_get
|
45
|
+
return unless state.is_execution_traced?
|
46
|
+
stared_event = operations.delete(event.operation_id)
|
47
|
+
one_apm_generate_metrics(stared_event, event.duration)
|
48
|
+
one_apm_notice_statement(stared_event, operator_type, event.duration)
|
49
|
+
one_apm_notice_sql(state, stared_event, operator_type, event.duration)
|
50
|
+
rescue => e
|
51
|
+
log_operations_error(operator_type, e)
|
52
|
+
end
|
49
53
|
end
|
50
|
-
rescue => e
|
51
|
-
OneApm::Manager.logger.debug("Exception during Mongo statement gathering", e)
|
52
|
-
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
def one_apm_generate_metrics(event, duration)
|
56
|
+
base, *other_metrics = mertircs(event)
|
57
|
+
OneApm::Manager.agent.stats_engine.tl_record_scoped_and_unscoped_metrics(
|
58
|
+
base, other_metrics, duration
|
59
|
+
)
|
60
|
+
end
|
58
61
|
|
59
|
-
|
60
|
-
|
62
|
+
def one_apm_notice_sql(state, event, status, duration)
|
63
|
+
stack = state.traced_method_stack
|
64
|
+
base, *other_metrics = mertircs(event)
|
61
65
|
|
62
|
-
|
66
|
+
started_time = Time.now.to_f
|
67
|
+
frame = stack.push_frame(state, :mongo_tracer, started_time)
|
63
68
|
|
64
|
-
|
65
|
-
|
69
|
+
builder = state.transaction_sample_builder
|
70
|
+
format_sql = OneApm::Agent::Datastore::Mongo::CommandFormatter.format_sql(event, status)
|
71
|
+
OneApm::Manager.agent.transaction_sampler.send(:notice_extra_data, builder, format_sql, duration, :sql)
|
66
72
|
|
67
|
-
|
68
|
-
|
73
|
+
stack.pop_frame(state, frame, base, started_time + duration)
|
74
|
+
end
|
69
75
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
one_apm_notice_statement(t0, method_name)
|
76
|
-
result
|
76
|
+
def one_apm_notice_statement(event, status, duration)
|
77
|
+
statement = OneApm::Agent::Datastore::Mongo::CommandFormatter.format(event, status)
|
78
|
+
if statement
|
79
|
+
OneApm::Manager.agent.transaction_sampler.notice_nosql_statement(statement, duration)
|
77
80
|
end
|
78
|
-
|
81
|
+
rescue => e
|
82
|
+
OneApm::Manager.logger.debug("Exception during Mongo statement gathering", e)
|
79
83
|
end
|
80
|
-
|
81
|
-
|
84
|
+
|
85
|
+
def log_operations_error(event_type, error)
|
86
|
+
OneApm::Manager.logger.error("Error during MongoDB #{event_type} event:")
|
87
|
+
OneApm::Manager.logger.log_exception(:error, error)
|
88
|
+
end
|
89
|
+
|
82
90
|
end
|
83
91
|
end
|
84
|
-
|
85
92
|
end
|
86
|
-
|
87
93
|
end
|
94
|
+
|
95
|
+
LibraryDetection.defer do
|
96
|
+
named :mongo2
|
97
|
+
|
98
|
+
depends_on do
|
99
|
+
require 'one_apm/agent/datastore/mongo'
|
100
|
+
defined?(::Mongo) && OneApm::Agent::Datastore::Mongo.is_support_version2? && !OneApm::Manager.config[:disable_mongo]
|
101
|
+
end
|
102
|
+
|
103
|
+
executes do
|
104
|
+
OneApm::Manager.logger.info 'Installing Mongo 2 instrumentation'
|
105
|
+
install_mongo_command_subscriber
|
106
|
+
end
|
107
|
+
|
108
|
+
def install_mongo_command_subscriber
|
109
|
+
require 'one_apm/agent/datastore/metric_helper'
|
110
|
+
require 'one_apm/agent/datastore/mongo/command_formatter'
|
111
|
+
::Mongo::Monitoring::Global.subscribe(
|
112
|
+
::Mongo::Monitoring::COMMAND,
|
113
|
+
OneApm::Agent::Instrumentation::MongoCommandSubscriber.new
|
114
|
+
)
|
115
|
+
end
|
116
|
+
end
|
data/lib/one_apm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oneapm_rpm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- oneapm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -258,6 +258,7 @@ files:
|
|
258
258
|
- lib/one_apm/agent/datastore.rb
|
259
259
|
- lib/one_apm/agent/datastore/metric_helper.rb
|
260
260
|
- lib/one_apm/agent/datastore/mongo.rb
|
261
|
+
- lib/one_apm/agent/datastore/mongo/command_formatter.rb
|
261
262
|
- lib/one_apm/agent/datastore/mongo/metric_translator.rb
|
262
263
|
- lib/one_apm/agent/datastore/mongo/obfuscator.rb
|
263
264
|
- lib/one_apm/agent/datastore/mongo/statement_formatter.rb
|