Module: Oboe::XTrace

Defined in:
lib/oboe/xtrace.rb

Class Method Summary collapse

Class Method Details

.task_id(xtrace) ⇒ Object

Oboe::XTrace.task_id

Extract and return the task_id portion of an X-Trace ID



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/oboe/xtrace.rb', line 37

def task_id(xtrace)
  begin
    return nil unless Oboe::XTrace.valid?(xtrace)

    xtrace[2..41]
  rescue StandardError => e
    Oboe.logger.debug e.message
    Oboe.logger.debug e.backtrace
    return nil
  end
end

.valid?(xtrace) ⇒ Boolean

Oboe::XTrace.valid?

Perform basic validation on a potential X-Trace ID

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/oboe/xtrace.rb', line 13

def valid?(xtrace)
  begin
    # Shouldn't be nil
    return false unless xtrace

    # The X-Trace ID shouldn't be an initialized empty ID
    return false if (xtrace =~ /^1b0000000/i) == 0

    # Valid X-Trace IDs have a length of 58 bytes and start with '1b'
    return false unless xtrace.length == 58 and (xtrace =~ /^1b/i) == 0

    true
  rescue StandardError => e
    Oboe.logger.debug e.message
    Oboe.logger.debug e.backtrace
    false
  end
end