Class: Imprint::Tracer
- Inherits:
-
Object
- Object
- Imprint::Tracer
- Defined in:
- lib/imprint/tracer.rb
Constant Summary collapse
- TRACER_HEADER =
'HTTP_IMPRINTID'- TRACER_KEY =
'IMPRINTID'- RAILS_REQUEST_ID =
"action_dispatch.request_id"- TRACE_ID_DEFAULT =
"-1"- TRACER_TIMESTAMP =
"TIMESTAMP"
Class Method Summary collapse
- .get_pid ⇒ Object
- .get_trace_id ⇒ Object
- .get_trace_timestamp ⇒ Object
- .insert_trace_id_in_message(message, severity = nil) ⇒ Object
- .rand_trace_id ⇒ Object
- .set_trace_id(id, rack_env = {}) ⇒ Object
Class Method Details
.get_pid ⇒ Object
30 31 32 |
# File 'lib/imprint/tracer.rb', line 30 def self.get_pid "#{$$}" end |
.get_trace_id ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/imprint/tracer.rb', line 18 def self.get_trace_id if Thread.current.key?(TRACER_KEY) Thread.current[TRACER_KEY] else TRACE_ID_DEFAULT end end |
.get_trace_timestamp ⇒ Object
26 27 28 |
# File 'lib/imprint/tracer.rb', line 26 def self. Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%6N") end |
.insert_trace_id_in_message(message, severity = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/imprint/tracer.rb', line 34 def self.(, severity = nil) if && .is_a?(String) && .length > 1 && !.include?('trace_id=') trace_id = get_trace_id if trace_id && trace_id != TRACE_ID_DEFAULT .insert 0, "#{get_trace_timestamp} #{severity} " .gsub!("\n"," process_pid=#{get_pid} trace_id=#{trace_id}\n") end end end |
.rand_trace_id ⇒ Object
45 46 47 |
# File 'lib/imprint/tracer.rb', line 45 def self.rand_trace_id SecureRandom.uuid end |
.set_trace_id(id, rack_env = {}) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/imprint/tracer.rb', line 11 def self.set_trace_id(id, rack_env = {}) Thread.current[TRACER_TIMESTAMP] = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%6N") Thread.current[TRACER_KEY] = id # setting to the rack_env, gives error tracking support in some systems rack_env[TRACER_KEY] = id end |