Module: Datadog::Contrib::MongoDB
- Defined in:
- lib/ddtrace/contrib/mongodb/parsers.rb,
lib/ddtrace/contrib/mongodb/patcher.rb,
lib/ddtrace/contrib/mongodb/subscribers.rb
Overview
MongoDB module includes classes and functions to instrument MongoDB clients
Defined Under Namespace
Modules: Patcher Classes: MongoCommandSubscriber
Constant Summary collapse
- SKIP_KEYS =
skipped keys are related to command names, since they are already extracted by the query_builder
[:_id].freeze
- PLACEHOLDER =
'?'.freeze
- APP =
'mongodb'.freeze
- SERVICE =
'mongodb'.freeze
Class Method Summary collapse
-
.quantize_statement(statement, skip = []) ⇒ Object
removes the values from the given query; this quantization recursively replace elements available in a given query, so that Arrays, Hashes and so on are compacted.
- .quantize_value(value, skip = []) ⇒ Object
-
.query_builder(command_name, database_name, command) ⇒ Object
returns a formatted and normalized query.
Class Method Details
.quantize_statement(statement, skip = []) ⇒ Object
removes the values from the given query; this quantization recursively replace elements available in a given query, so that Arrays, Hashes and so on are compacted. It ensures a low cardinality so that it can be used as a Span resource.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ddtrace/contrib/mongodb/parsers.rb', line 34 def quantize_statement(statement, skip = []) case statement when Hash statement.each_with_object({}) do |(key, value), quantized| quantized[key] = quantize_value(value, skip) unless skip.include?(key) end else quantize_value(statement, skip) end end |
.quantize_value(value, skip = []) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ddtrace/contrib/mongodb/parsers.rb', line 45 def quantize_value(value, skip = []) case value when Hash quantize_statement(value, skip) when Array quantize_value(value.first, skip) else PLACEHOLDER end end |
.query_builder(command_name, database_name, command) ⇒ Object
returns a formatted and normalized query
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ddtrace/contrib/mongodb/parsers.rb', line 13 def query_builder(command_name, database_name, command) # always skip the command name skip = SKIP_KEYS | [command_name.to_s] result = { operation: command_name, database: database_name, collection: command.values.first } command.each do |key, value| result[key] = quantize_statement(value, skip) unless skip.include?(key) end result end |