Class: Sentry::MetricEvent

Inherits:
Object
  • Object
show all
Includes:
Utils::TelemetryAttributes
Defined in:
lib/sentry/metric_event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, value:, unit: nil, attributes: nil) ⇒ MetricEvent

Returns a new instance of MetricEvent.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sentry/metric_event.rb', line 12

def initialize(
  name:,
  type:,
  value:,
  unit: nil,
  attributes: nil
)
  @name = name
  @type = type
  @value = value
  @unit = unit
  @attributes = attributes || {}

  @timestamp = Sentry.utc_now
  @trace_id = nil
  @span_id = nil
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



9
10
11
# File 'lib/sentry/metric_event.rb', line 9

def attributes
  @attributes
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/sentry/metric_event.rb', line 9

def name
  @name
end

#span_idObject

Returns the value of attribute span_id.



9
10
11
# File 'lib/sentry/metric_event.rb', line 9

def span_id
  @span_id
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



9
10
11
# File 'lib/sentry/metric_event.rb', line 9

def timestamp
  @timestamp
end

#trace_idObject

Returns the value of attribute trace_id.



9
10
11
# File 'lib/sentry/metric_event.rb', line 9

def trace_id
  @trace_id
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/sentry/metric_event.rb', line 9

def type
  @type
end

#unitObject (readonly)

Returns the value of attribute unit.



9
10
11
# File 'lib/sentry/metric_event.rb', line 9

def unit
  @unit
end

#valueObject (readonly)

Returns the value of attribute value.



9
10
11
# File 'lib/sentry/metric_event.rb', line 9

def value
  @value
end

Instance Method Details

#to_hObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sentry/metric_event.rb', line 30

def to_h
  {
    name: @name,
    type: @type,
    value: @value,
    unit: @unit,
    timestamp: @timestamp,
    trace_id: @trace_id,
    span_id: @span_id,
    attributes: serialize_attributes
  }.compact
end