Sha256: 4a9c49890f8434e2d131259a9d004861d2775f43c3880e4fd89410f81469cc25

Contents?: true

Size: 1021 Bytes

Versions: 2

Compression:

Stored size: 1021 Bytes

Contents

# frozen_string_literal: true

# Copyright 2019 OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

module OpenTelemetry
  module Instrumentation
    module Mongo
      # Instrumentation class that detects and installs the Mongo instrumentation
      class Instrumentation < OpenTelemetry::Instrumentation::Base
        MINIMUM_VERSION = Gem::Version.new('2.5.0')

        install do |_config|
          require_dependencies
          register_subscriber
        end

        present do
          !defined?(::Mongo::Monitoring::Global).nil? && gem_version >= MINIMUM_VERSION
        end

        private

        def gem_version
          Gem.loaded_specs['mongo']&.version
        end

        def require_dependencies
          require_relative 'subscriber'
        end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-mongo-0.10.0 lib/opentelemetry/instrumentation/mongo/instrumentation.rb
opentelemetry-instrumentation-mongo-0.9.0 lib/opentelemetry/instrumentation/mongo/instrumentation.rb