Sha256: f136d3ee446ad398c53d15a85d590e2583d4eb14fd0cdf439bbf95304f48f470

Contents?: true

Size: 1022 Bytes

Versions: 17

Compression:

Stored size: 1022 Bytes

Contents

require 'ddtrace/contrib/patcher'
require 'ddtrace/contrib/mongodb/ext'
require 'ddtrace/contrib/mongodb/instrumentation'

module Datadog
  module Contrib
    module MongoDB
      # Patcher enables patching of 'mongo' module.
      module Patcher
        include Contrib::Patcher

        module_function

        def patched?
          done?(:mongo)
        end

        def patch
          do_once(:mongo) do
            begin
              ::Mongo::Address.send(:include, Instrumentation::Address)
              ::Mongo::Client.send(:include, Instrumentation::Client)
              add_mongo_monitoring
            rescue StandardError => e
              Datadog::Tracer.log.error("Unable to apply MongoDB integration: #{e}")
            end
          end
        end

        def add_mongo_monitoring
          # Subscribe to all COMMAND queries with our subscriber class
          ::Mongo::Monitoring::Global.subscribe(::Mongo::Monitoring::COMMAND, MongoCommandSubscriber.new)
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
ls-trace-0.1.2 lib/ddtrace/contrib/mongodb/patcher.rb
ddtrace-0.29.1 lib/ddtrace/contrib/mongodb/patcher.rb
ddtrace-0.26.1 lib/ddtrace/contrib/mongodb/patcher.rb
ls-trace-0.1.1 lib/ddtrace/contrib/mongodb/patcher.rb
ddtrace-0.29.0 lib/ddtrace/contrib/mongodb/patcher.rb
ddtrace-0.28.0 lib/ddtrace/contrib/mongodb/patcher.rb
ddtrace-0.27.0 lib/ddtrace/contrib/mongodb/patcher.rb
ddtrace-0.26.0 lib/ddtrace/contrib/mongodb/patcher.rb
ddtrace-0.25.1 lib/ddtrace/contrib/mongodb/patcher.rb
ddtrace-0.25.0 lib/ddtrace/contrib/mongodb/patcher.rb
ddtrace-0.24.0 lib/ddtrace/contrib/mongodb/patcher.rb
ddtrace-0.23.3 lib/ddtrace/contrib/mongodb/patcher.rb
ddtrace-0.23.2 lib/ddtrace/contrib/mongodb/patcher.rb
ddtrace-0.23.1 lib/ddtrace/contrib/mongodb/patcher.rb
ddtrace-0.23.0 lib/ddtrace/contrib/mongodb/patcher.rb
ddtrace-0.22.0 lib/ddtrace/contrib/mongodb/patcher.rb
ddtrace-0.21.2 lib/ddtrace/contrib/mongodb/patcher.rb