Class: Brut::FrontEnd::Handlers::InstrumentationHandler::Span

Inherits:
Data
  • Object
show all
Defined in:
lib/brut/front_end/handlers/instrumentation_handler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes

Returns:

  • (Object)

    the current value of attributes



12
13
14
# File 'lib/brut/front_end/handlers/instrumentation_handler.rb', line 12

def attributes
  @attributes
end

#end_timestampObject (readonly)

Returns the value of attribute end_timestamp

Returns:

  • (Object)

    the current value of end_timestamp



12
13
14
# File 'lib/brut/front_end/handlers/instrumentation_handler.rb', line 12

def end_timestamp
  @end_timestamp
end

#eventsObject (readonly)

Returns the value of attribute events

Returns:

  • (Object)

    the current value of events



12
13
14
# File 'lib/brut/front_end/handlers/instrumentation_handler.rb', line 12

def events
  @events
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



12
13
14
# File 'lib/brut/front_end/handlers/instrumentation_handler.rb', line 12

def name
  @name
end

#spansObject (readonly)

Returns the value of attribute spans

Returns:

  • (Object)

    the current value of spans



12
13
14
# File 'lib/brut/front_end/handlers/instrumentation_handler.rb', line 12

def spans
  @spans
end

#start_timestampObject (readonly)

Returns the value of attribute start_timestamp

Returns:

  • (Object)

    the current value of start_timestamp



12
13
14
# File 'lib/brut/front_end/handlers/instrumentation_handler.rb', line 12

def start_timestamp
  @start_timestamp
end

Class Method Details

.from_header(header_value) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/brut/front_end/handlers/instrumentation_handler.rb', line 23

def self.from_header(header_value)
  if header_value.nil?
    return nil
  end
  if header_value.kind_of?(self)
    return header_value
  end

  # This header can have info for several vendors, delimited by commas. We pick
  # out ours, which has a vendor name 'brut'
  brut_state = header_value.split(/\s*,\s*/).map { it.split(/\s*=\s*/) }.detect { |vendor,_|
    vendor == "brut"
  }[1]

  # Our state is a base-64 encoded JSON blob
  # each key/value separated by a colon.
  json = Base64.decode64(brut_state)

  hash = JSON.parse(json)
  if !hash.kind_of?(Hash)
    SemanticLogger[self.class].info "Got a #{hash.class} and not a Hash"
    return nil
  end
  self.from_json(hash)
end

.from_json(json) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/brut/front_end/handlers/instrumentation_handler.rb', line 13

def self.from_json(json)
  name            = json["name"]
  start_timestamp = Time.at(json["start_timestamp"].to_i / 1000.0)
  end_timestamp   = Time.at(json["end_timestamp"].to_i / 1000.0)
  attributes      = json["attributes"] || {}
  events          = (json["events"] || []).map { Event.from_json(it) }
  spans           = (json["spans"] || []).map { Span.from_json(it) }
  self.new(name:,start_timestamp:,end_timestamp:,attributes:,events:,spans:)
end