Sha256: fe99052d44f956fb414dfbbd9d43641ee5efffeb4bba633a0ccd53da9dd01b94

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

module Datadog
  module Tracing
    module Contrib
      # Registry is a collection of tracing integrations.
      # @public_api
      class Registry
        include Enumerable

        Entry = Struct.new(:name, :klass, :auto_patch)

        # @!visibility private
        def initialize
          @data = {}
          @mutex = Mutex.new
        end

        # @param name [Symbol] instrumentation name, to be used when activating this integration
        # @param klass [Object] instrumentation implementation
        # @param auto_patch [Boolean] is the tracer allowed to automatically patch
        #   the host application with this instrumentation?
        def add(name, klass, auto_patch = false)
          @mutex.synchronize do
            @data[name] = Entry.new(name, klass, auto_patch).freeze
          end
        end

        def each(&block)
          @mutex.synchronize do
            @data.each_value(&block)
          end
        end

        def [](name)
          @mutex.synchronize do
            entry = @data[name]
            entry.klass if entry
          end
        end

        def to_h
          @mutex.synchronize do
            @data.each_with_object({}) do |(_, entry), hash|
              hash[entry.name] = entry.auto_patch
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ddtrace-1.10.1 lib/datadog/tracing/contrib/registry.rb
ddtrace-1.10.0 lib/datadog/tracing/contrib/registry.rb