Module: Datadog::Contrib::MongoDB

Defined in:
lib/ddtrace/contrib/mongodb/parsers.rb,
lib/ddtrace/contrib/mongodb/ext.rb,
lib/ddtrace/contrib/mongodb/patcher.rb,
lib/ddtrace/contrib/mongodb/integration.rb,
lib/ddtrace/contrib/mongodb/subscribers.rb,
lib/ddtrace/contrib/mongodb/instrumentation.rb,
lib/ddtrace/contrib/mongodb/configuration/settings.rb

Overview

MongoDB module includes classes and functions to instrument MongoDB clients

Defined Under Namespace

Modules: Configuration, Ext, Instrumentation, Patcher Classes: Integration, MongoCommandSubscriber

Constant Summary collapse

EXCLUDE_KEYS =
[:_id].freeze
SHOW_KEYS =
[].freeze
DEFAULT_OPTIONS =
{ exclude: EXCLUDE_KEYS, show: SHOW_KEYS }.freeze
PLACEHOLDER =

skipped keys are related to command names, since they are already extracted by the query_builder

'?'.freeze

Class Method Summary collapse

Class Method Details

.configurationObject



63
64
65
# File 'lib/ddtrace/contrib/mongodb/parsers.rb', line 63

def configuration
  Datadog.configuration[:mongo]
end

.quantization_optionsObject



59
60
61
# File 'lib/ddtrace/contrib/mongodb/parsers.rb', line 59

def quantization_options
  Datadog::Quantization::Hash.merge_options(DEFAULT_OPTIONS, configuration[:quantize])
end

.quantize_statement(statement, skip = []) ⇒ Object

Deprecated.

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.



36
37
38
39
40
41
42
43
44
45
# File 'lib/ddtrace/contrib/mongodb/parsers.rb', line 36

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

Deprecated.


48
49
50
51
52
53
54
55
56
57
# File 'lib/ddtrace/contrib/mongodb/parsers.rb', line 48

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



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ddtrace/contrib/mongodb/parsers.rb', line 16

def query_builder(command_name, database_name, command)
  # always exclude the command name
  options = Quantization::Hash.merge_options(quantization_options, exclude: [command_name.to_s])

  # quantized statements keys are strings to avoid leaking Symbols in older Rubies
  # as Symbols are not GC'ed in Rubies prior to 2.2
  base_info = Quantization::Hash.format({
                                          'operation' => command_name,
                                          'database' => database_name,
                                          'collection' => command.values.first
                                        }, options)

  base_info.merge(Quantization::Hash.format(command, options))
end