Class: Datadog::Core::Telemetry::Metric::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/core/telemetry/metric.rb

Overview

Base class for all metric types

Direct Known Subclasses

Count, Distribution, IntervalMetric

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, tags: {}, common: true) ⇒ Base

Returns a new instance of Base.

Parameters:

  • name (String)

    metric name

  • tags (Array<String>|Hash{String=>String}) (defaults to: {})

    metric tags as hash or array of “tag:val” strings

  • common (Boolean) (defaults to: true)

    true if the metric is common for all languages, false for Ruby-specific metric



15
16
17
18
19
20
# File 'lib/datadog/core/telemetry/metric.rb', line 15

def initialize(name, tags: {}, common: true)
  @name = name
  @values = []
  @tags = tags_to_array(tags)
  @common = common
end

Instance Attribute Details

#commonObject (readonly)

Returns the value of attribute common.



10
11
12
# File 'lib/datadog/core/telemetry/metric.rb', line 10

def common
  @common
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/datadog/core/telemetry/metric.rb', line 10

def name
  @name
end

#tagsObject (readonly)

Returns the value of attribute tags.



10
11
12
# File 'lib/datadog/core/telemetry/metric.rb', line 10

def tags
  @tags
end

#valuesObject (readonly)

Returns the value of attribute values.



10
11
12
# File 'lib/datadog/core/telemetry/metric.rb', line 10

def values
  @values
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



44
45
46
47
48
# File 'lib/datadog/core/telemetry/metric.rb', line 44

def ==(other)
  other.is_a?(self.class) &&
    name == other.name &&
    values == other.values && tags == other.tags && common == other.common && type == other.type
end

#hashObject



52
53
54
# File 'lib/datadog/core/telemetry/metric.rb', line 52

def hash
  [self.class, name, values, tags, common, type].hash
end

#idObject



22
23
24
# File 'lib/datadog/core/telemetry/metric.rb', line 22

def id
  @id ||= "#{type}::#{name}::#{tags.join(',')}"
end

#to_hObject



34
35
36
37
38
39
40
41
42
# File 'lib/datadog/core/telemetry/metric.rb', line 34

def to_h
  {
    metric: name,
    points: values,
    type: type,
    tags: tags,
    common: common
  }
end

#track(value) ⇒ Object

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/datadog/core/telemetry/metric.rb', line 26

def track(value)
  raise NotImplementedError, 'method must be implemented in subclasses'
end

#typeObject

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/datadog/core/telemetry/metric.rb', line 30

def type
  raise NotImplementedError, 'method must be implemented in subclasses'
end