Class: MetrixWire::Span

Inherits:
Object
  • Object
show all
Defined in:
lib/metrixwire/span.rb

Overview

A single unit of work within a trace (db_query | http_call | custom). Users never build these by hand — instrumentation creates them.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, description:, started_at:, duration_ms:, source_location: nil, meta: nil) ⇒ Span

Returns a new instance of Span.

Parameters:

  • type (String)

    "db_query" | "http_call" | "custom"

  • started_at (String)

    ISO8601

  • meta (Hash, nil) (defaults to: nil)

    optional signal (e.g. { rowCount: }, { statusCode: })



12
13
14
15
16
17
18
19
# File 'lib/metrixwire/span.rb', line 12

def initialize(type:, description:, started_at:, duration_ms:, source_location: nil, meta: nil)
  @type = type
  @description = description
  @started_at = started_at
  @duration_ms = duration_ms
  @source_location = source_location
  @meta = meta
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



7
8
9
# File 'lib/metrixwire/span.rb', line 7

def description
  @description
end

#duration_msObject (readonly)

Returns the value of attribute duration_ms.



7
8
9
# File 'lib/metrixwire/span.rb', line 7

def duration_ms
  @duration_ms
end

#metaObject (readonly)

Returns the value of attribute meta.



7
8
9
# File 'lib/metrixwire/span.rb', line 7

def meta
  @meta
end

#source_locationObject (readonly)

Returns the value of attribute source_location.



7
8
9
# File 'lib/metrixwire/span.rb', line 7

def source_location
  @source_location
end

#started_atObject (readonly)

Returns the value of attribute started_at.



7
8
9
# File 'lib/metrixwire/span.rb', line 7

def started_at
  @started_at
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/metrixwire/span.rb', line 7

def type
  @type
end

Instance Method Details

#to_hObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/metrixwire/span.rb', line 21

def to_h
  out = {
    type: @type,
    description: @description,
    startedAt: @started_at,
    durationMs: @duration_ms
  }
  out[:sourceLocation] = @source_location if @source_location
  out[:meta] = @meta if @meta && !@meta.empty?
  out
end