sleuth 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/sleuth.rb +3 -4
- data/lib/sleuth/event.rb +21 -0
- data/lib/sleuth/outbound_handler.rb +3 -1
- data/lib/sleuth/transaction.rb +0 -21
- metadata +4 -3
data/lib/sleuth.rb
CHANGED
@@ -10,8 +10,6 @@ require 'time'
|
|
10
10
|
module Sleuth
|
11
11
|
TRANSACTION_HEADER = "X_SLEUTH_TRANSACTION"
|
12
12
|
|
13
|
-
class OutsideTransaction < StandardError; end
|
14
|
-
|
15
13
|
class << self
|
16
14
|
delegate :head, :get, :post, :put, :delete, :to => :http
|
17
15
|
|
@@ -27,7 +25,7 @@ module Sleuth
|
|
27
25
|
yield
|
28
26
|
end
|
29
27
|
else
|
30
|
-
|
28
|
+
yield
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
@@ -63,7 +61,7 @@ module Sleuth
|
|
63
61
|
def watch(log_path)
|
64
62
|
logger = ActiveSupport::BufferedLogger.new(log_path)
|
65
63
|
subscribe do |event|
|
66
|
-
logger.debug(
|
64
|
+
logger.debug(event.message)
|
67
65
|
end
|
68
66
|
end
|
69
67
|
|
@@ -78,4 +76,5 @@ end
|
|
78
76
|
current_dir = File.expand_path(File.dirname(__FILE__) + '/sleuth')
|
79
77
|
require current_dir + '/middleware'
|
80
78
|
require current_dir + '/outbound_handler'
|
79
|
+
require current_dir + '/event'
|
81
80
|
require current_dir + '/transaction'
|
data/lib/sleuth/event.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Sleuth
|
2
|
+
class Event < ActiveSupport::Notifications::Event
|
3
|
+
def formatted_time
|
4
|
+
"%s%06d" % [time.utc.iso8601, time.usec]
|
5
|
+
end
|
6
|
+
|
7
|
+
def formatted_end
|
8
|
+
"%s%06d" % [@end.utc.iso8601, @end.usec]
|
9
|
+
end
|
10
|
+
|
11
|
+
def transaction
|
12
|
+
Transaction.running[transaction_id]
|
13
|
+
end
|
14
|
+
|
15
|
+
def message
|
16
|
+
parts = [formatted_time, formatted_end, transaction.full_name,
|
17
|
+
transaction.parent || '-', duration, payload.inspect]
|
18
|
+
"%s %s %s %s %0.4f -- %s" % parts
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -7,7 +7,9 @@ module Sleuth
|
|
7
7
|
def call(env)
|
8
8
|
request = Rack::Request.new(env)
|
9
9
|
Sleuth.instrument("Sending #{request.request_method} #{request.url}") do
|
10
|
-
|
10
|
+
if Sleuth.inside_transaction?
|
11
|
+
env["HTTP_#{TRANSACTION_HEADER}"] = Sleuth.current_transaction.full_name
|
12
|
+
end
|
11
13
|
@app.call(env)
|
12
14
|
end
|
13
15
|
end
|
data/lib/sleuth/transaction.rb
CHANGED
@@ -1,14 +1,4 @@
|
|
1
1
|
module Sleuth
|
2
|
-
class Event < ActiveSupport::Notifications::Event
|
3
|
-
def formatted_time
|
4
|
-
"%s%06d" % [time.utc.iso8601, time.usec]
|
5
|
-
end
|
6
|
-
|
7
|
-
def formatted_end
|
8
|
-
"%s%06d" % [@end.utc.iso8601, @end.usec]
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
2
|
class Transaction < Struct.new(:name, :id, :stamp, :pid, :parent)
|
13
3
|
mattr_reader :running
|
14
4
|
@@running = {}
|
@@ -18,17 +8,6 @@ module Sleuth
|
|
18
8
|
running[id] = new(name, id, Time.now.to_i, Process.pid, parent)
|
19
9
|
end
|
20
10
|
|
21
|
-
def self.message_for(event)
|
22
|
-
transaction = running[event.transaction_id]
|
23
|
-
transaction.message_for(event)
|
24
|
-
end
|
25
|
-
|
26
|
-
def message_for(event)
|
27
|
-
parts = [event.formatted_time, event.formatted_end,
|
28
|
-
full_name, parent || '-', event.duration, event.payload.inspect]
|
29
|
-
"%s %s %s %s %0.4f -- %s" % parts
|
30
|
-
end
|
31
|
-
|
32
11
|
def full_name
|
33
12
|
"#{name}-#{id}-#{stamp}-#{pid}"
|
34
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sleuth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Carey-Smith
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-06 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
version_requirement:
|
29
29
|
version_requirements: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.2.0
|
34
34
|
version:
|
@@ -41,6 +41,7 @@ extensions: []
|
|
41
41
|
extra_rdoc_files: []
|
42
42
|
|
43
43
|
files:
|
44
|
+
- lib/sleuth/event.rb
|
44
45
|
- lib/sleuth/middleware.rb
|
45
46
|
- lib/sleuth/outbound_handler.rb
|
46
47
|
- lib/sleuth/transaction.rb
|