Module: Skylight::Core::Instrumentable::ClassMethods

Defined in:
lib/skylight/core/instrumentable.rb

Instance Method Summary collapse

Instance Method Details

#broken!Object



146
147
148
149
# File 'lib/skylight/core/instrumentable.rb', line 146

def broken!
  return unless instrumenter
  instrumenter.broken!
end

#configObject



161
162
163
164
# File 'lib/skylight/core/instrumentable.rb', line 161

def config
  return unless instrumenter
  instrumenter.config
end

#correlation_headerObject



26
27
28
# File 'lib/skylight/core/instrumentable.rb', line 26

def correlation_header
  nil
end

#disableObject

Temporarily disable



152
153
154
155
156
157
158
159
# File 'lib/skylight/core/instrumentable.rb', line 152

def disable
  unless instrumenter
    return yield if block_given?
    return
  end

  instrumenter.disable { yield }
end

#done(span, meta = nil) ⇒ Object

End a span



141
142
143
144
# File 'lib/skylight/core/instrumentable.rb', line 141

def done(span, meta = nil)
  return unless instrumenter
  instrumenter.done(span, meta)
end

#enable_normalizer(*names) ⇒ Object



34
35
36
# File 'lib/skylight/core/instrumentable.rb', line 34

def enable_normalizer(*names)
  Skylight::Core::Normalizers.enable(*names)
end

#instrument(opts = DEFAULT_OPTIONS, &block) ⇒ Object

Instrument



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/skylight/core/instrumentable.rb', line 111

def instrument(opts = DEFAULT_OPTIONS, &block)
  unless instrumenter
    return yield if block_given?
    return
  end

  if opts.is_a?(Hash)
    category    = opts[:category] || DEFAULT_CATEGORY
    title       = opts[:title]
    desc        = opts[:description]
    meta        = opts[:meta]
    if opts.key?(:annotations)
      warn "call to #instrument included deprecated annotations"
    end
  else
    category    = DEFAULT_CATEGORY
    title       = opts.to_s
    desc        = nil
    meta        = nil
  end

  instrumenter.instrument(category, title, desc, meta, &block)
end

#instrumenterObject



22
23
24
# File 'lib/skylight/core/instrumentable.rb', line 22

def instrumenter
  defined?(@instrumenter) && @instrumenter
end

#instrumenter_classObject



18
19
20
# File 'lib/skylight/core/instrumentable.rb', line 18

def instrumenter_class
  Skylight::Core::Instrumenter
end

#probe(*args) ⇒ Object



30
31
32
# File 'lib/skylight/core/instrumentable.rb', line 30

def probe(*args)
  Skylight::Core::Probes.probe(*args)
end

#span_correlation_header(span) ⇒ Object



135
136
137
138
# File 'lib/skylight/core/instrumentable.rb', line 135

def span_correlation_header(span)
  return unless instrumenter
  instrumenter.span_correlation_header(span)
end

#start!(config = nil) ⇒ Object

Start instrumenting



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/skylight/core/instrumentable.rb', line 39

def start!(config = nil)
  return instrumenter if instrumenter

  const_get(:LOCK).synchronize do
    return instrumenter if instrumenter

    config ||= {}
    config = config_class.load(config) unless config.is_a?(config_class)

    @instrumenter = instrumenter_class.new(config).start!
  end
rescue => e
  level, message =
    if e.is_a?(ConfigError)
      [:warn, format("Unable to start Instrumenter due to a configuration error: %<message>s",
                     message: e.message)]
    else
      [:error, format("Unable to start Instrumenter; msg=%<message>s; class=%<klass>s",
                      message: e.message, klass: e.class)]
    end

  if config && config.respond_to?("log_#{level}") && config.respond_to?(:log_trace)
    config.send("log_#{level}", message)
    config.log_trace e.backtrace.join("\n")
  else
    warn "[#{name.upcase}] #{message}"
  end
  false
end

#started?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/skylight/core/instrumentable.rb', line 69

def started?
  !!instrumenter
end

#stop!Object

Stop instrumenting



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/skylight/core/instrumentable.rb', line 74

def stop!
  t { "stop!" }

  const_get(:LOCK).synchronize do
    t { "stop! synchronized" }
    return unless instrumenter
    # This is only really helpful for getting specs to pass.
    @instrumenter.current_trace = nil

    @instrumenter.shutdown
    @instrumenter = nil
  end
end

#trace(endpoint = nil, cat = nil, title = nil, meta: nil, segment: nil) ⇒ Object

Start a trace



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/skylight/core/instrumentable.rb', line 95

def trace(endpoint = nil, cat = nil, title = nil, meta: nil, segment: nil)
  unless instrumenter
    return yield if block_given?
    return
  end

  cat ||= DEFAULT_CATEGORY

  if block_given?
    instrumenter.trace(endpoint, cat, title, nil, meta: meta, segment: segment) { |tr| yield tr }
  else
    instrumenter.trace(endpoint, cat, title, nil, meta: meta, segment: segment)
  end
end

#tracing?Boolean

Check tracing

Returns:

  • (Boolean)


89
90
91
92
# File 'lib/skylight/core/instrumentable.rb', line 89

def tracing?
  t { "checking tracing?; thread=#{Thread.current.object_id}" }
  instrumenter && instrumenter.current_trace
end