Module: InstrumentAllTheThings

Defined in:
lib/instrument_all_the_things/testing/rspec_matchers.rb,
lib/instrument_all_the_things.rb,
lib/instrument_all_the_things/context.rb,
lib/instrument_all_the_things/helpers.rb,
lib/instrument_all_the_things/version.rb,
lib/instrument_all_the_things/method_proxy.rb,
lib/instrument_all_the_things/method_instrumentor.rb,
lib/instrument_all_the_things/testing/stat_tracker.rb,
lib/instrument_all_the_things/instrumentors/tracing.rb,
lib/instrument_all_the_things/testing/trace_tracker.rb,
lib/instrument_all_the_things/clients/tracer/blackhole.rb,
lib/instrument_all_the_things/instrumentors/error_logging.rb,
lib/instrument_all_the_things/clients/stat_reporter/datadog.rb,
lib/instrument_all_the_things/instrumentors/execution_count_and_timing.rb

Overview

rubocop:todo Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

Defined Under Namespace

Modules: Clients, Helpers, Instrumentors, MethodProxy, Testing Classes: Context, Error, MethodInstrumentor

Constant Summary collapse

VERSION =
'5.0.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/instrument_all_the_things.rb', line 18

def logger
  return @logger if defined?(@logger)

  @logger ||= if defined?(Rails) && Rails.respond_to?(:logger)
                Rails.logger
              elsif defined?(App) && App.respond_to?(:logger)
                App.logger
              else
                require 'logger'
                Logger.new($stdout)
              end
end

.stat_namespaceObject

Returns the value of attribute stat_namespace.



15
16
17
# File 'lib/instrument_all_the_things.rb', line 15

def stat_namespace
  @stat_namespace
end

.stat_reporterObject



31
32
33
34
35
# File 'lib/instrument_all_the_things.rb', line 31

def stat_reporter
  @stat_reporter ||= Clients::StatReporter::DataDog.new(
    namespace: stat_namespace,
  )
end

.tracerObject



37
38
39
# File 'lib/instrument_all_the_things.rb', line 37

def tracer
  Datadog::Tracing
end

Class Method Details

.included(other) ⇒ Object



60
61
62
# File 'lib/instrument_all_the_things.rb', line 60

def self.included(other)
  other.include(Helpers)
end

.tag_active_span(tag_name, tag_value) ⇒ Object



64
65
66
# File 'lib/instrument_all_the_things.rb', line 64

def self.tag_active_span(tag_name, tag_value)
  tracer&.active_span&.set_tags(to_tracer_tags(tag_name => tag_value))
end

.to_tracer_tags(hsh, prefix = nil) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/instrument_all_the_things.rb', line 68

def self.to_tracer_tags(hsh, prefix = nil)
  hsh.each_with_object({}) do |(hash_key, value), acc|
    key = prefix ? "#{prefix}.#{hash_key}" : hash_key

    case value
    when Hash
      acc.merge!(to_tracer_tags(value, key))
    when Array
      content = value.each_with_index.each_with_object({}) do |(item, index), reformed|
        reformed[index] = item
      end

      acc.merge!(to_tracer_tags(content, key))
    else
      acc[key] = value
    end
  end
end