imprint 1.4.2 → 1.4.3.pre

Sign up to get free protection for your applications and to get access to all the features.
data/imprint.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "shoulda"
24
24
  spec.add_development_dependency "rack"
25
25
  spec.add_development_dependency "simplecov"
26
+ spec.add_development_dependency "timecop"
26
27
  end
@@ -4,10 +4,12 @@ module Imprint
4
4
  TRACER_KEY = 'IMPRINTID'
5
5
  RAILS_REQUEST_ID = "action_dispatch.request_id"
6
6
  TRACE_ID_DEFAULT = "-1"
7
-
7
+ TRACER_TIMESTAMP = "TIMESTAMP"
8
+
8
9
  TRACE_CHARS = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
9
10
 
10
11
  def self.set_trace_id(id, rack_env = {})
12
+ Thread.current[TRACER_TIMESTAMP] ||= Time.now.to_f
11
13
  Thread.current[TRACER_KEY] = id
12
14
  # setting to the rack_env, gives error tracking support in some systems
13
15
  rack_env[TRACER_KEY] = id
@@ -21,11 +23,18 @@ module Imprint
21
23
  end
22
24
  end
23
25
 
26
+ def self.get_trace_timestamp
27
+ Thread.current[TRACER_TIMESTAMP] ||= Time.now.to_f
28
+ end
29
+
24
30
  def self.insert_trace_id_in_message(message)
25
31
  if message && message.is_a?(String) && message.length > 1 && !message.include?('trace_id=')
26
32
  trace_id = get_trace_id
27
33
 
28
- message.gsub!("\n"," trace_id=#{trace_id}\n") if trace_id && trace_id != TRACE_ID_DEFAULT
34
+ if trace_id && trace_id != TRACE_ID_DEFAULT
35
+ message.insert 0, "[#{get_trace_timestamp}] "
36
+ message.gsub!("\n"," trace_id=#{trace_id}\n")
37
+ end
29
38
  end
30
39
  end
31
40
 
@@ -1,3 +1,3 @@
1
1
  module Imprint
2
- VERSION = "1.4.2"
2
+ VERSION = "1.4.3.pre"
3
3
  end
data/test/test_helper.rb CHANGED
@@ -3,6 +3,7 @@ require 'simplecov'
3
3
  require 'minitest/autorun'
4
4
  require 'shoulda'
5
5
  require 'rack'
6
+ require 'timecop'
6
7
 
7
8
  SimpleCov.start do
8
9
  add_filter 'specs/ruby/1.9.1/gems/'
@@ -8,6 +8,17 @@ class TracerTest < Minitest::Test
8
8
  assert_equal fake_trace, Imprint::Tracer.get_trace_id
9
9
  end
10
10
 
11
+ should "set trace timestamp" do
12
+ fake_trace = "tracer"
13
+ Timecop.freeze do
14
+ test_time = Time.now
15
+ Imprint::Tracer.set_trace_id(fake_trace, fake_rack_env)
16
+ # timecop has a bug with millisec time on osx
17
+ # this makes the check ignore millisec
18
+ assert !!Imprint::Tracer.get_trace_timestamp.to_s.match(/#{test_time.to_i.to_s}/)
19
+ end
20
+ end
21
+
11
22
  should "get trace id defaults" do
12
23
  assert_equal Imprint::Tracer::TRACE_ID_DEFAULT, Imprint::Tracer.get_trace_id
13
24
  Imprint::Tracer.set_trace_id("fake_trace", fake_rack_env)
@@ -16,6 +27,15 @@ class TracerTest < Minitest::Test
16
27
  assert_equal Imprint::Tracer::TRACE_ID_DEFAULT, Imprint::Tracer.get_trace_id
17
28
  end
18
29
 
30
+ should "get trace timestamp defaults" do
31
+ Timecop.freeze do
32
+ test_time = Time.now
33
+ # timecop has a bug with millisec time on osx
34
+ # this makes the check ignore millisec
35
+ assert !!Imprint::Tracer.get_trace_timestamp.to_s.match(/#{test_time.to_i.to_s}/)
36
+ end
37
+ end
38
+
19
39
  should "generate rand trace id" do
20
40
  trace_id = Imprint::Tracer.rand_trace_id
21
41
  refute_nil trace_id
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imprint
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
5
- prerelease:
4
+ version: 1.4.3.pre
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dan Mayer
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-29 00:00:00.000000000 Z
12
+ date: 2015-04-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -91,6 +91,22 @@ dependencies:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: timecop
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
94
110
  description: A gem to help improve logging. Focused on request tracing and cross app
95
111
  tracing.
96
112
  email:
@@ -132,16 +148,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
148
  version: '0'
133
149
  segments:
134
150
  - 0
135
- hash: -2434163442242259334
151
+ hash: 689667875995530347
136
152
  required_rubygems_version: !ruby/object:Gem::Requirement
137
153
  none: false
138
154
  requirements:
139
- - - ! '>='
155
+ - - ! '>'
140
156
  - !ruby/object:Gem::Version
141
- version: '0'
142
- segments:
143
- - 0
144
- hash: -2434163442242259334
157
+ version: 1.3.1
145
158
  requirements: []
146
159
  rubyforge_project:
147
160
  rubygems_version: 1.8.23