Class: Kirei::Logging::Metric

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/kirei/logging/metric.rb

Class Method Summary collapse

Class Method Details

.call(metric_name, value = 1, tags: {}) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/kirei/logging/metric.rb', line 16

def self.call(metric_name, value = 1, tags: {})
  return if ENV["NO_METRICS"] == "true"

  inject_defaults(tags)

  # Do not `compact_blank` tags, since one might want to track empty strings/"false"/NULLs.
  # NOT having any tag doesn't tell the user if the tag was empty or not set at all.
  StatsD.increment(metric_name, value, tags: tags)
end

.inject_defaults(tags) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kirei/logging/metric.rb', line 27

def self.inject_defaults(tags)
  App.config.metric_default_tags.each_pair do |key, default_value|
    tags[key] ||= default_value
  end

  tags["enduser.id"] ||= Thread.current[:enduser_id]
  tags["service.name"] ||= Kirei::App.config.app_name # OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME
  tags["service.version"] = Kirei::App.version # OpenTelemetry::SemanticConventions::Resource::SERVICE_VERSION

  tags
end