Module: Skylight::Core::Instrumentable::ClassMethods
- Defined in:
- lib/skylight/core/instrumentable.rb
Instance Method Summary collapse
- #broken! ⇒ Object
- #config ⇒ Object
- #correlation_header ⇒ Object
-
#disable ⇒ Object
Temporarily disable.
-
#done(span, meta = nil) ⇒ Object
End a span.
- #enable_normalizer(*names) ⇒ Object
-
#instrument(opts = DEFAULT_OPTIONS, &block) ⇒ Object
Instrument.
- #instrumenter ⇒ Object
- #instrumenter_class ⇒ Object
- #mute ⇒ Object
- #muted? ⇒ Boolean
- #probe(*args) ⇒ Object
- #span_correlation_header(span) ⇒ Object
-
#spawn_shutdown_thread! ⇒ Object
Runs the shutdown procedure in the background.
-
#start!(config = nil) ⇒ Object
Start instrumenting.
- #started? ⇒ Boolean
-
#stop! ⇒ Object
Stop instrumenting.
-
#trace(endpoint = nil, cat = nil, title = nil, meta: nil, segment: nil, component: nil) ⇒ Object
Start a trace.
-
#tracing? ⇒ Boolean
Check tracing.
- #unmute ⇒ Object
Instance Method Details
#broken! ⇒ Object
178 179 180 181 |
# File 'lib/skylight/core/instrumentable.rb', line 178 def broken! return unless instrumenter instrumenter.broken! end |
#config ⇒ Object
193 194 195 196 |
# File 'lib/skylight/core/instrumentable.rb', line 193 def config return unless instrumenter instrumenter.config end |
#correlation_header ⇒ Object
26 27 28 |
# File 'lib/skylight/core/instrumentable.rb', line 26 def correlation_header nil end |
#disable ⇒ Object
Temporarily disable
184 185 186 187 188 189 190 191 |
# File 'lib/skylight/core/instrumentable.rb', line 184 def disable unless instrumenter return yield if block_given? return end instrumenter.disable { yield } end |
#done(span, meta = nil) ⇒ Object
End a span
173 174 175 176 |
# File 'lib/skylight/core/instrumentable.rb', line 173 def done(span, = nil) return unless instrumenter instrumenter.done(span, ) 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
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/skylight/core/instrumentable.rb', line 117 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] = opts[:meta] if opts.key?(:annotations) warn "call to #instrument included deprecated annotations" end else category = DEFAULT_CATEGORY title = opts.to_s desc = nil = nil end instrumenter.instrument(category, title, desc, , &block) end |
#instrumenter ⇒ Object
22 23 24 |
# File 'lib/skylight/core/instrumentable.rb', line 22 def instrumenter defined?(@instrumenter) && @instrumenter end |
#instrumenter_class ⇒ Object
18 19 20 |
# File 'lib/skylight/core/instrumentable.rb', line 18 def instrumenter_class Skylight::Core::Instrumenter end |
#mute ⇒ Object
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/skylight/core/instrumentable.rb', line 141 def mute unless instrumenter return yield if block_given? return end instrumenter.mute do yield if block_given? end end |
#muted? ⇒ Boolean
163 164 165 |
# File 'lib/skylight/core/instrumentable.rb', line 163 def muted? instrumenter&.muted? 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
167 168 169 170 |
# File 'lib/skylight/core/instrumentable.rb', line 167 def span_correlation_header(span) return unless instrumenter instrumenter.span_correlation_header(span) end |
#spawn_shutdown_thread! ⇒ Object
Runs the shutdown procedure in the background. This should do little more than unsubscribe from all ActiveSupport::Notifications
200 201 202 203 204 |
# File 'lib/skylight/core/instrumentable.rb', line 200 def spawn_shutdown_thread! @shutdown_thread || const_get(:LOCK).synchronize do @shutdown_thread ||= Thread.new { @instrumenter&.shutdown } end 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, = if e.is_a?(ConfigError) [:warn, format("Unable to start Instrumenter due to a configuration error: %<message>s", message: e.)] else [:error, format("Unable to start Instrumenter; msg=%<message>s; class=%<klass>s", message: e., klass: e.class)] end if config && config.respond_to?("log_#{level}") && config.respond_to?(:log_trace) config.send("log_#{level}", ) config.log_trace e.backtrace.join("\n") else warn "[#{name.upcase}] #{}" end false end |
#started? ⇒ 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, component: nil) ⇒ Object
Start a trace
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/skylight/core/instrumentable.rb', line 95 def trace(endpoint = nil, cat = nil, title = nil, meta: nil, segment: nil, component: nil) unless instrumenter return yield if block_given? return end if instrumenter.poisoned? spawn_shutdown_thread! return yield if block_given? return end cat ||= DEFAULT_CATEGORY if block_given? instrumenter.trace(endpoint, cat, title, nil, meta: , segment: segment, component: component) { |tr| yield tr } else instrumenter.trace(endpoint, cat, title, nil, meta: , segment: segment, component: component) end end |
#tracing? ⇒ Boolean
Check tracing
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 |
#unmute ⇒ Object
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/skylight/core/instrumentable.rb', line 152 def unmute unless instrumenter return yield if block_given? return end instrumenter.unmute do yield if block_given? end end |