ecin-rack-probe 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rack/probe.rb +10 -4
- data/rack-probe.gemspec +2 -2
- data/spec/rack/probe_spec.rb +22 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/rack/probe.rb
CHANGED
@@ -24,15 +24,19 @@ module Rack
|
|
24
24
|
p.probe :path, :string # Path visited
|
25
25
|
p.probe :referer, :string # Referer
|
26
26
|
p.probe :xhr # AJAX request
|
27
|
+
|
28
|
+
p.probe :request_start # Start of a request
|
29
|
+
p.probe :request_finish # End of a request
|
27
30
|
end
|
28
|
-
|
29
|
-
# Provider shortcut
|
30
|
-
@R = Dtrace::Probe::Rack
|
31
31
|
end
|
32
|
+
|
33
|
+
# Provider shortcut
|
34
|
+
@R = Dtrace::Probe::Rack
|
32
35
|
@app = app
|
33
36
|
end
|
34
37
|
|
35
38
|
def call( env )
|
39
|
+
@R.request_start(&:fire)
|
36
40
|
request = Rack::Request.new env
|
37
41
|
@R.get(&:fire) if request.get?
|
38
42
|
@R.post(&:fire) if request.post?
|
@@ -42,7 +46,9 @@ module Rack
|
|
42
46
|
@R.path { |p| p.fire(request.path) }
|
43
47
|
@R.ip { |p| p.fire(request.ip) }
|
44
48
|
@R.referer { |p| p.fire(request.referer) }
|
45
|
-
@app.call
|
49
|
+
response = @app.call(env)
|
50
|
+
@R.request_finish(&:fire)
|
51
|
+
response
|
46
52
|
end
|
47
53
|
|
48
54
|
end
|
data/rack-probe.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rack-probe}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["ecin"]
|
12
|
-
s.date = %q{2009-08-
|
12
|
+
s.date = %q{2009-08-21}
|
13
13
|
s.description = %q{Rack::Probe provides a set of probes for Rack that fire with each request.}
|
14
14
|
s.email = %q{ecin@copypastel.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/rack/probe_spec.rb
CHANGED
@@ -24,11 +24,13 @@ describe Rack::Probe do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
before :each do
|
27
|
+
@q = Proc.new {'hello'}
|
27
28
|
@compiler = Dtrace.new
|
28
29
|
@compiler.setopt('bufsize', '8m')
|
29
30
|
end
|
30
31
|
|
31
32
|
it 'should fire a probe with a request\'s ip' do
|
33
|
+
Rack::Probe.new @q
|
32
34
|
consumer = compile_script ":::ip {trace(copyinstr((int) arg0));}"
|
33
35
|
get '/'
|
34
36
|
consumer.consume_once do |d|
|
@@ -110,5 +112,25 @@ describe Rack::Probe do
|
|
110
112
|
end
|
111
113
|
consumer.finished?.should be_true
|
112
114
|
end
|
115
|
+
|
116
|
+
it 'should fire a probe when a request is started' do
|
117
|
+
consumer = compile_script ":::request_start {}"
|
118
|
+
get '/'
|
119
|
+
consumer.consume_once do |d|
|
120
|
+
d.probe.name.should eql('request_start')
|
121
|
+
consumer.finish
|
122
|
+
end
|
123
|
+
consumer.finished?.should be_true
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should fire a probe when a request finishes' do
|
127
|
+
consumer = compile_script ":::request_finish {}"
|
128
|
+
get '/'
|
129
|
+
consumer.consume_once do |d|
|
130
|
+
d.probe.name.should eql('request_finish')
|
131
|
+
consumer.finish
|
132
|
+
end
|
133
|
+
consumer.finished?.should be_true
|
134
|
+
end
|
113
135
|
|
114
136
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecin-rack-probe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ecin
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|