imprint 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/imprint.rb +5 -5
- data/lib/imprint/middleware.rb +3 -3
- data/lib/imprint/version.rb +1 -1
- data/test/unit/middleware_test.rb +2 -2
- data/test/unit/tracer_test.rb +11 -3
- metadata +4 -4
data/lib/imprint.rb
CHANGED
@@ -8,14 +8,14 @@ module Imprint
|
|
8
8
|
|
9
9
|
TRACE_CHARS = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
|
10
10
|
|
11
|
-
def self.set_trace_id(id,
|
12
|
-
|
11
|
+
def self.set_trace_id(id, rack_env = {})
|
12
|
+
Thread.current[TRACER_KEY] = id
|
13
|
+
# setting to the rack_env, gives error tracking support in some systems
|
13
14
|
rack_env[TRACER_KEY] = id
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
rails_env[TRACER_KEY]
|
17
|
+
def self.get_trace_id
|
18
|
+
Thread.current[TRACER_KEY]
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.rand_trace_id
|
data/lib/imprint/middleware.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Imprint
|
2
2
|
class Middleware
|
3
3
|
|
4
|
-
def self.
|
4
|
+
def self.set_request_trace_id(rack_env)
|
5
5
|
existing_id = rack_env[Imprint::Tracer::TRACER_HEADER]
|
6
6
|
existing_id ||= "#{Time.now.to_i}_#{Imprint::Tracer.rand_trace_id}"
|
7
|
-
Imprint::Tracer.set_trace_id(existing_id,
|
7
|
+
Imprint::Tracer.set_trace_id(existing_id, rack_env)
|
8
8
|
end
|
9
9
|
|
10
10
|
def initialize(app, opts = {})
|
@@ -12,7 +12,7 @@ module Imprint
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def call(env)
|
15
|
-
::Imprint::Middleware.
|
15
|
+
::Imprint::Middleware.set_request_trace_id(env)
|
16
16
|
@app.call(env)
|
17
17
|
end
|
18
18
|
|
data/lib/imprint/version.rb
CHANGED
@@ -20,8 +20,8 @@ class MiddlewareTest < Test::Unit::TestCase
|
|
20
20
|
middleware = Imprint::Middleware.new(fake_app)
|
21
21
|
results = middleware.call(request)
|
22
22
|
assert_equal "/anything.json", results.last
|
23
|
-
assert_not_nil ::Imprint::Tracer.get_trace_id
|
24
|
-
assert ::Imprint::Tracer.get_trace_id
|
23
|
+
assert_not_nil ::Imprint::Tracer.get_trace_id
|
24
|
+
assert ::Imprint::Tracer.get_trace_id!='-1'
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
data/test/unit/tracer_test.rb
CHANGED
@@ -4,12 +4,14 @@ class TracerTest < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
should "set trace id" do
|
6
6
|
fake_trace = "tracer"
|
7
|
-
Imprint::Tracer.set_trace_id(fake_trace,
|
8
|
-
assert_equal fake_trace, Imprint::Tracer.get_trace_id
|
7
|
+
Imprint::Tracer.set_trace_id(fake_trace, fake_rack_env)
|
8
|
+
assert_equal fake_trace, Imprint::Tracer.get_trace_id
|
9
9
|
end
|
10
10
|
|
11
11
|
should "get trace id defaults" do
|
12
|
-
assert_not_nil Imprint::Tracer.get_trace_id
|
12
|
+
assert_not_nil Imprint::Tracer.get_trace_id
|
13
|
+
Imprint::Tracer.set_trace_id(nil, fake_rack_env)
|
14
|
+
assert_equal nil, Imprint::Tracer.get_trace_id
|
13
15
|
end
|
14
16
|
|
15
17
|
should "generate rand trace id" do
|
@@ -19,4 +21,10 @@ class TracerTest < Test::Unit::TestCase
|
|
19
21
|
assert trace_id.match(/[A-Za-z]/)
|
20
22
|
end
|
21
23
|
|
24
|
+
protected
|
25
|
+
|
26
|
+
def fake_rack_env
|
27
|
+
{}
|
28
|
+
end
|
29
|
+
|
22
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imprint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -144,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
segments:
|
146
146
|
- 0
|
147
|
-
hash:
|
147
|
+
hash: -3002848166108194027
|
148
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
149
|
none: false
|
150
150
|
requirements:
|
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
153
|
version: '0'
|
154
154
|
segments:
|
155
155
|
- 0
|
156
|
-
hash:
|
156
|
+
hash: -3002848166108194027
|
157
157
|
requirements: []
|
158
158
|
rubyforge_project:
|
159
159
|
rubygems_version: 1.8.23
|