Class: Mnemosyne::Instrumenter
- Inherits:
-
Object
- Object
- Mnemosyne::Instrumenter
- Includes:
- Logging
- Defined in:
- lib/mnemosyne/instrumenter.rb
Constant Summary collapse
- IDENT =
:__mnemosyne_current_trace
- MUTEX =
Mutex.new
Class Attribute Summary collapse
-
.instance ⇒ Object
readonly
Returns the value of attribute instance.
Class Method Summary collapse
- .current_trace ⇒ Object
- .start!(config = nil) ⇒ Object
- .trace(*args) ⇒ Object
- .with(instrumenter) ⇒ Object
Instance Method Summary collapse
- #current_trace ⇒ Object
- #current_trace=(trace) ⇒ Object
-
#initialize(config:, client:) ⇒ Instrumenter
constructor
A new instance of Instrumenter.
- #release(trace) ⇒ Object
- #submit(trace) ⇒ Object
- #trace(name, **kwargs) ⇒ Object
Methods included from Logging
Constructor Details
#initialize(config:, client:) ⇒ Instrumenter
Returns a new instance of Instrumenter.
10 11 12 13 14 15 16 17 |
# File 'lib/mnemosyne/instrumenter.rb', line 10 def initialize(config:, client:) @client = client @config = config ::Mnemosyne::Probes.activate! logger.debug(Mnemosyne) { 'Instrumenter started' } end |
Class Attribute Details
.instance ⇒ Object (readonly)
Returns the value of attribute instance.
59 60 61 |
# File 'lib/mnemosyne/instrumenter.rb', line 59 def instance @instance end |
Class Method Details
.current_trace ⇒ Object
94 95 96 97 98 |
# File 'lib/mnemosyne/instrumenter.rb', line 94 def current_trace return unless (instrumenter = instance) instrumenter.current_trace end |
.start!(config = nil) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/mnemosyne/instrumenter.rb', line 61 def start!(config = nil) return @instance if @instance MUTEX.synchronize do return @instance if @instance client = Client.new(config) @instance = new(config: config, client: client) end rescue StandardError => e ::Mnemosyne::Logging.logger.warn(Mnemosyne) do "Unable to start instrumenter: #{e}" end raise end |
.trace(*args) ⇒ Object
88 89 90 91 92 |
# File 'lib/mnemosyne/instrumenter.rb', line 88 def trace(*args) return unless (instrumenter = instance) instrumenter.trace(*args) end |
.with(instrumenter) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/mnemosyne/instrumenter.rb', line 79 def with(instrumenter) old = instance @instance = instrumenter yield(instrumenter) ensure @instance = old end |
Instance Method Details
#current_trace ⇒ Object
19 20 21 |
# File 'lib/mnemosyne/instrumenter.rb', line 19 def current_trace Thread.current[IDENT] end |
#current_trace=(trace) ⇒ Object
23 24 25 |
# File 'lib/mnemosyne/instrumenter.rb', line 23 def current_trace=(trace) Thread.current[IDENT] = trace end |
#release(trace) ⇒ Object
52 53 54 55 56 |
# File 'lib/mnemosyne/instrumenter.rb', line 52 def release(trace) return unless current_trace.equal?(trace) self.current_trace = nil end |
#submit(trace) ⇒ Object
46 47 48 49 50 |
# File 'lib/mnemosyne/instrumenter.rb', line 46 def submit(trace) logger.debug(Mnemosyne) { "Submit trace #{trace.uuid}" } @client.call trace end |
#trace(name, **kwargs) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mnemosyne/instrumenter.rb', line 27 def trace(name, **kwargs) if (trace = current_trace) return yield trace if block_given? return trace end trace = self.current_trace = Trace.new(self, name, kwargs) return trace unless block_given? begin yield trace ensure self.current_trace = nil trace.submit end end |