class Datadog::Pin

A Pin (a.k.a Patch INfo) is a small class which is used to set tracing metadata on a particular traced object. This is useful if you wanted to, say, trace two different database clusters.

Constants

DEPRECATION_WARNING
DEPRECATION_WARN_ONLY_ONCE

Attributes

app[RW]
app_type[RW]
config[RW]
name[RW]
service=[RW]
service_name[RW]
tags[RW]
writer[RW]

Public Class Methods

get_from(obj) click to toggle source
# File lib/ddtrace/pin.rb, line 14
def self.get_from(obj)
  return nil unless obj.respond_to? :datadog_pin

  obj.datadog_pin
end
new(service_name, options = {}) click to toggle source
# File lib/ddtrace/pin.rb, line 25
def initialize(service_name, options = {})
  deprecation_warning unless options[:tracer].is_a?(Proc) || options[:tracer].nil?

  @app = options[:app]
  @app_type = options[:app_type]
  @config = options[:config]
  @name = nil # this would rarely be overriden as it's really span-specific
  @service_name = service_name
  @tags = options[:tags]
  @tracer = options[:tracer]
end

Public Instance Methods

datadog_pin() click to toggle source
# File lib/ddtrace/pin.rb, line 59
def datadog_pin
  @datadog_pin
end
datadog_pin=(pin) click to toggle source
# File lib/ddtrace/pin.rb, line 51
def datadog_pin=(pin)
  @datadog_pin = pin
end
enabled?() click to toggle source
# File lib/ddtrace/pin.rb, line 41
def enabled?
  return tracer.enabled if tracer

  false
end
onto(obj) click to toggle source

rubocop:disable Style/TrivialAccessors

# File lib/ddtrace/pin.rb, line 48
def onto(obj)
  unless obj.respond_to? :datadog_pin=
    obj.instance_exec do
      def datadog_pin=(pin)
        @datadog_pin = pin
      end
    end
  end

  unless obj.respond_to? :datadog_pin
    obj.instance_exec do
      def datadog_pin
        @datadog_pin
      end
    end
  end

  obj.datadog_pin = self
end
to_s() click to toggle source
# File lib/ddtrace/pin.rb, line 68
def to_s
  "Pin(service:#{service},app:#{app},app_type:#{app_type},name:#{name})"
end
tracer() click to toggle source
# File lib/ddtrace/pin.rb, line 37
def tracer
  @tracer.is_a?(Proc) ? @tracer.call : (@tracer || Datadog.tracer)
end

Private Instance Methods

deprecation_warning() click to toggle source
# File lib/ddtrace/pin.rb, line 80
def deprecation_warning
  DEPRECATION_WARN_ONLY_ONCE.run do
    Datadog.logger.warn("Datadog::Pin.new:#{DEPRECATION_WARNING}")
  end
end