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.

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.



23
24
25
26
27
28
29
30
31
# File 'lib/ddtrace/pin.rb', line 23

def initialize(service_name, options = {})
  @app = options[:app]
  @tags = options[:tags]
  @app_type = options[:app_type]
  @name = nil # this would rarely be overriden as it's really span-specific
  @tracer = options[:tracer] || Datadog.tracer
  @config = options[:config]
  self.service_name = service_name
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



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

def app
  @app
end

#app_typeObject

Returns the value of attribute app_type.



18
19
20
# File 'lib/ddtrace/pin.rb', line 18

def app_type
  @app_type
end

#configObject

Returns the value of attribute config.



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

def config
  @config
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#service_nameObject Also known as: service

Returns the value of attribute service_name.



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

def service_name
  @service_name
end

#tagsObject

Returns the value of attribute tags.



17
18
19
# File 'lib/ddtrace/pin.rb', line 17

def tags
  @tags
end

#tracerObject

Returns the value of attribute tracer.



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

def tracer
  @tracer
end

Class Method Details

.get_from(obj) ⇒ Object



10
11
12
13
# File 'lib/ddtrace/pin.rb', line 10

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

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/ddtrace/pin.rb', line 33

def enabled?
  return @tracer.enabled if @tracer
  false
end

#onto(obj) ⇒ Object

rubocop:disable Style/TrivialAccessors



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ddtrace/pin.rb', line 39

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



66
67
68
# File 'lib/ddtrace/pin.rb', line 66

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