oneapm_rpm 1.2.9 → 1.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmNkNTY0Y2FhZjMxMWRmZDI4YWNjYjZlNmI0ODgwMjc3ODA3YWI4ZA==
4
+ NzJkZmRlMGY5MmE5ZWM1MzBiMWQzOGI4OTU2MzM5OTEzYmU2OTE2NQ==
5
5
  data.tar.gz: !binary |-
6
- ZDE0MmRlZGZhNjY1ZTE0ZWRkM2QzOWZhNGFlNGVjMjM1ZDk4NjY0ZQ==
6
+ ZTE2ZWUwMGRhZDg5ZjdhZjNjNzlkY2UzYmUxYjBkNjQyODEwOTY0OQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDk5NzdiOTA5NWY5OWUwODAzNGY4OTA0NjZiNjlmMDVhYjFiMDg4ZDgwMmNl
10
- Y2RlZjJkMWRmODkxYmM0ZmFmMGNhZTUyMDQzOTkyZjYxZjk5NjRhNGY1NGNl
11
- ZDEzNTI3N2FhZmVkMDBhNGU3YzkyYzMzOGJjMDE3YzZiZDc1NGU=
9
+ NzMyNDAzNDliNmYwZTdhNDI4OTNmMDUxN2UyNWRmOWMxZWU5OTUwOWFjMWJk
10
+ N2IxYTIzN2ZiNDg4ODU5OGJkZjIyMmY4NzdkYWNmZjVkMDRkMzBiNzgwMGVk
11
+ YjQ0MDA1NDVmY2U1ZTIyZDUyNmQ4YWQ1NGQ4YTc0Mjc5Y2Q0ZDU=
12
12
  data.tar.gz: !binary |-
13
- ZDAwOThmMjM3ZjhmZmI3OTIyOWNhOTdkM2E3N2VlOWQ5NWRlMTFhZDc3M2Zm
14
- NWE2NjA1YWFjZTMwYjdkNTRlMDA0NzdmYzU1ZDJkYTNjYTVkNzBkNGFiOGIx
15
- YzgzOTk4M2RhNzc1MWVhYzdkYjQ0ODEyYTY3OWU4M2MxMmY3NDA=
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
- LibraryDetection.defer do
4
- named :mongo2
5
-
6
- depends_on do
7
- require 'one_apm/agent/datastore/mongo'
8
- defined?(::Mongo) && OneApm::Agent::Datastore::Mongo.is_version2? && !OneApm::Manager.config[:disable_mongo]
9
- end
10
-
11
- executes do
12
- OneApm::Manager.logger.info 'Installing Mongo 2 instrumentation'
13
- install_mongo_instrumentation
14
- end
15
-
16
- def install_mongo_instrumentation
17
- require 'one_apm/agent/datastore/mongo/metric_translator'
18
- require 'one_apm/agent/datastore/mongo/statement_formatter'
19
- hook_instrument_method_for_collection
20
- hook_instrument_method_for_view
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
- def hook_instrument_method_for_view
30
- methods = [:count, :distinct, :map_reduce,:find_one_and_delete, :find_one_and_replace, :find_one_and_update,
31
- :delete_many, :delete_one, :replace_one, :update_many, :update_one]
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
- def instrument_methods_with_oneapm klass, methods
37
- klass.class_eval do
38
- include OneApm::Support::MethodTracer
32
+ def operations
33
+ @operations ||= {}
34
+ end
39
35
 
40
- def payload_for_oneapm
41
- collection = self.name rescue self.collection.name
42
- @payload_for_oneapm ||= { :collection => collection, :database => self.database.name }
43
- end
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
- def one_apm_notice_statement(t0, name)
46
- statement = OneApm::Agent::Datastore::Mongo::StatementFormatter.format(payload_for_oneapm, name)
47
- if statement
48
- OneApm::Manager.agent.transaction_sampler.notice_nosql_statement(statement, (Time.now - t0).to_f)
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
- def one_apm_generate_metrics(operation)
55
- OneApm::Agent::Datastore::Mongo::MetricTranslator.metrics_for(operation, payload_for_oneapm)
56
- end
57
- end
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
- methods.each do |method_name|
60
- next unless klass.method_defined?(method_name)
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
- klass.class_eval do
66
+ started_time = Time.now.to_f
67
+ frame = stack.push_frame(state, :mongo_tracer, started_time)
63
68
 
64
- method_name_without_oneapm = :"#{method_name}_without_oneapm"
65
- method_name_with_oneapm = :"#{method_name}_with_oneapm"
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
- define_method method_name_with_oneapm do |*args, &block|
68
- metrics = one_apm_generate_metrics(method_name)
73
+ stack.pop_frame(state, frame, base, started_time + duration)
74
+ end
69
75
 
70
- trace_execution_scoped(metrics) do
71
- t0 = Time.now
72
- result = OneApm::Manager.disable_all_tracing do
73
- send method_name_without_oneapm, *args, &block
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
- alias_method method_name_without_oneapm, method_name.to_sym
81
- alias_method method_name.to_sym, method_name_with_oneapm
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
@@ -4,12 +4,13 @@ module OneApm
4
4
  module VERSION
5
5
 
6
6
  MAJOR = 1
7
- MINOR = 2
8
- TINY = 9
7
+ MINOR = 3
8
+ TINY = 0
9
+ TAG = 'rc1'
9
10
 
10
11
 
11
12
 
12
- STRING = [MAJOR, MINOR, TINY].compact.join('.')
13
+ STRING = [MAJOR, MINOR, TINY, TAG].compact.join('.')
13
14
 
14
15
  end
15
16
  end
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.2.9
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-20 00:00:00.000000000 Z
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