Module: Sleuth
- Defined in:
- lib/sleuth.rb,
lib/sleuth/event.rb,
lib/sleuth/middleware.rb,
lib/sleuth/transaction.rb,
lib/sleuth/outbound_handler.rb
Defined Under Namespace
Classes: Event, Middleware, OutboundHeader, Transaction
Constant Summary
collapse
"X_SLEUTH_TRANSACTION"
Class Method Summary
collapse
Class Method Details
.current_id ⇒ Object
41
42
43
|
# File 'lib/sleuth.rb', line 41
def current_id
ActiveSupport::Notifications.transaction_id
end
|
.current_transaction ⇒ Object
45
46
47
|
# File 'lib/sleuth.rb', line 45
def current_transaction
Transaction.running[current_id]
end
|
.http ⇒ Object
17
18
19
20
21
|
# File 'lib/sleuth.rb', line 17
def http
@http ||= Rack::Client.new {
use OutboundHeader
}
end
|
.inside_transaction? ⇒ Boolean
49
50
51
|
# File 'lib/sleuth.rb', line 49
def inside_transaction?
current_transaction
end
|
.instrument(payload) ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/sleuth.rb', line 23
def instrument(payload)
if inside_transaction?
ActiveSupport::Notifications.instrument(:sleuth, payload) do
yield
end
else
yield
end
end
|
.subscribe ⇒ Object
69
70
71
72
73
|
# File 'lib/sleuth.rb', line 69
def subscribe
ActiveSupport::Notifications.subscribe('sleuth') do |*args|
yield Event.new(*args)
end
end
|
.thread(name) ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'lib/sleuth.rb', line 53
def thread(name)
parent = current_transaction && current_transaction.full_name
Thread.new {
transaction(name, parent) do
yield
end
}
end
|
.transaction(current_name, parent = nil) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/sleuth.rb', line 33
def transaction(current_name, parent = nil)
ActiveSupport::Notifications.transaction do
Transaction.create(current_name, parent)
yield
end
end
|
.watch(log_path) ⇒ Object
62
63
64
65
66
67
|
# File 'lib/sleuth.rb', line 62
def watch(log_path)
logger = ActiveSupport::BufferedLogger.new(log_path)
subscribe do |event|
logger.debug(event.message)
end
end
|