Module: Dash0::OpenTelemetry::InstrumentationInstaller

Defined in:
lib/dash0/opentelemetry/instrumentation_installer.rb

Overview

Installs per-library instrumentation lazily via a TracePoint(:end): an initial sweep for already-loaded libraries, then a re-sweep each time a class or module finishes being defined, so a library loaded after us is still caught.

Ported, with light adaptation, from the upstream opentelemetry-auto-instrumentation gem's OTelInitializer (open-telemetry/opentelemetry-ruby-instrumentation), Apache-2.0.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.trace_pointObject (readonly)

Exposed for testing/inspection.



36
37
38
# File 'lib/dash0/opentelemetry/instrumentation_installer.rb', line 36

def trace_point
  @trace_point
end

Class Method Details

.enabled_instrumentation_namesObject

Returns the canonical instrumentation names enabled via OTEL_RUBY_ENABLED_INSTRUMENTATIONS, or [] when the variable is unset (meaning: install everything registered).



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dash0/opentelemetry/instrumentation_installer.rb', line 41

def enabled_instrumentation_names
  raw = ENV['OTEL_RUBY_ENABLED_INSTRUMENTATIONS'].to_s
  return [] if raw.strip.empty?

  lookup = registry_lookup
  raw.split(',').filter_map do |entry|
    normalized = entry.strip.downcase
    canonical = lookup[normalized]
    if canonical.nil? && ENV['DASH0_DEBUG'] == 'true'
      warn "#{Dash0::OpenTelemetry::LOG_PREFIX} Unknown instrumentation '#{entry.strip}'"
    end
    canonical
  end
end

.start(enabled_names = enabled_instrumentation_names) ⇒ Object

Sweeps once for already-loaded libraries, then — unless everything relevant is already installed — installs a TracePoint(:end) that re-sweeps whenever a class or module finishes being defined.

Parameters:

  • enabled_names (Array<String>) (defaults to: enabled_instrumentation_names)

    canonical instrumentation names to restrict installation to; empty means "all registered".



27
28
29
30
31
32
33
# File 'lib/dash0/opentelemetry/instrumentation_installer.rb', line 27

def start(enabled_names = enabled_instrumentation_names)
  sweep(enabled_names)
  return if relevant_instrumentations(enabled_names).all?(&:installed?)

  @trace_point = TracePoint.new(:end) { sweep(enabled_names) }
  @trace_point.enable
end