Class: RequestTracer::Trace::SpanId

Inherits:
Object
  • Object
show all
Defined in:
lib/request_tracer/trace.rb

Overview

A span represents one specific method call

Constant Summary collapse

HEX_REGEX =
/^[a-f0-9]{16}$/i
MAX_SIGNED_I64 =
9223372036854775807
MASK =
(2 ** 64) - 1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ SpanId

Returns a new instance of SpanId.



32
33
34
35
36
37
38
39
# File 'lib/request_tracer/trace.rb', line 32

def initialize(value)
  @value = value
  @i64 = if @value > MAX_SIGNED_I64
    -1 * ((@value ^ MASK) + 1)
  else
    @value
  end
end

Instance Attribute Details

#i64Object (readonly)

Returns the value of attribute i64.



31
32
33
# File 'lib/request_tracer/trace.rb', line 31

def i64
  @i64
end

#valueObject (readonly)

Returns the value of attribute value.



31
32
33
# File 'lib/request_tracer/trace.rb', line 31

def value
  @value
end

Class Method Details

.from_value(v) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/request_tracer/trace.rb', line 21

def self.from_value(v)
  if v.is_a?(String) && v =~ HEX_REGEX
    new(v.hex)
  elsif v.is_a?(Numeric)
    new(v)
  elsif v.is_a?(SpanId)
    v
  end
end

Instance Method Details

#==(other_span) ⇒ Object



41
42
43
# File 'lib/request_tracer/trace.rb', line 41

def ==(other_span)
  other_span && (other_span.value == @value)
end

#to_iObject



45
# File 'lib/request_tracer/trace.rb', line 45

def to_i; @i64; end

#to_sObject



44
# File 'lib/request_tracer/trace.rb', line 44

def to_s; "%016x" % @value; end