Class: Datadog::Pin

Inherits:
Object
  • Object
show all
Defined in:
lib/ddtrace/pin.rb

Overview

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.

Constant Summary collapse

DEPRECATION_WARN_ONLY_ONCE =
Datadog::Utils::OnlyOnce.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_name, options = {}) ⇒ Pin

Returns a new instance of Pin.



25
26
27
28
29
30
31
32
33
34
35
# 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

Instance Attribute Details

#appObject

Returns the value of attribute app.



20
21
22
# File 'lib/ddtrace/pin.rb', line 20

def app
  @app
end

#app_typeObject

Returns the value of attribute app_type.



20
21
22
# File 'lib/ddtrace/pin.rb', line 20

def app_type
  @app_type
end

#configObject

Returns the value of attribute config.



20
21
22
# File 'lib/ddtrace/pin.rb', line 20

def config
  @config
end

#nameObject

Returns the value of attribute name.



20
21
22
# File 'lib/ddtrace/pin.rb', line 20

def name
  @name
end

#service_nameObject Also known as: service

Returns the value of attribute service_name.



20
21
22
# File 'lib/ddtrace/pin.rb', line 20

def service_name
  @service_name
end

#tagsObject

Returns the value of attribute tags.



20
21
22
# File 'lib/ddtrace/pin.rb', line 20

def tags
  @tags
end

#writerObject

Returns the value of attribute writer.



20
21
22
# File 'lib/ddtrace/pin.rb', line 20

def writer
  @writer
end

Class Method Details

.get_from(obj) ⇒ Object



14
15
16
17
18
# File 'lib/ddtrace/pin.rb', line 14

def self.get_from(obj)
  return nil unless obj.respond_to? :datadog_pin

  obj.datadog_pin
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/ddtrace/pin.rb', line 41

def enabled?
  return tracer.enabled if tracer

  false
end

#onto(obj) ⇒ Object

rubocop:disable Style/TrivialAccessors



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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_sObject



68
69
70
# File 'lib/ddtrace/pin.rb', line 68

def to_s
  "Pin(service:#{service},app:#{app},app_type:#{app_type},name:#{name})"
end

#tracerObject



37
38
39
# File 'lib/ddtrace/pin.rb', line 37

def tracer
  @tracer.is_a?(Proc) ? @tracer.call : (@tracer || Datadog.tracer)
end