Class: LaunchDarklyObservability::InstrumentationLogFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/launchdarkly_observability/instrumentation_log_filter.rb

Overview

Wraps the OpenTelemetry logger to suppress the per-instrumentation install chatter ("... was successfully installed" / "... failed to install") and record the names of instrumentations that failed to install. Everything else (including level / level=) is delegated to the real logger.

OpenTelemetryConfig uses this to replace the SDK's flurry of per-instrumentation warnings with a single actionable summary.

Constant Summary collapse

FAILED_PATTERN =
/Instrumentation: (\S+) failed to install/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(delegate, failed) ⇒ InstrumentationLogFilter

Returns a new instance of InstrumentationLogFilter.



44
45
46
47
# File 'lib/launchdarkly_observability/instrumentation_log_filter.rb', line 44

def initialize(delegate, failed)
  @delegate = delegate
  @failed = failed
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



62
63
64
# File 'lib/launchdarkly_observability/instrumentation_log_filter.rb', line 62

def method_missing(name, ...)
  @delegate.send(name, ...)
end

Class Method Details

.capture_failuresObject

Run the block with OpenTelemetry.logger swapped for a filter that suppresses per-instrumentation install chatter, returning the names of any instrumentations that reported "failed to install". The SDK installs instrumentations after a configure block returns, so wrap the whole OpenTelemetry::SDK.configure call — not just use_all.



19
20
21
22
23
24
25
26
27
# File 'lib/launchdarkly_observability/instrumentation_log_filter.rb', line 19

def self.capture_failures
  original = OpenTelemetry.logger
  failed = []
  OpenTelemetry.logger = new(original, failed)
  yield
  failed
ensure
  OpenTelemetry.logger = original
end

.failure_warning(failed) ⇒ Object

Build ONE actionable warning naming the instrumentations that could not attach and how to resolve it. Telemetry that does not depend on those instrumentations (flag-eval spans, manual instrumentation, logs, errors) keeps working regardless.



33
34
35
36
37
38
39
40
41
42
# File 'lib/launchdarkly_observability/instrumentation_log_filter.rb', line 33

def self.failure_warning(failed)
  names = failed.map { |n| n.sub('OpenTelemetry::Instrumentation::', '') }.uniq
  rails = defined?(::Rails) && ::Rails.respond_to?(:version) ? " on Rails #{::Rails.version}" : ''
  "[LaunchDarklyObservability] #{names.size} OpenTelemetry instrumentation(s) could not attach" \
    "#{rails} (Ruby #{RUBY_VERSION}): #{names.join(', ')}. Those libraries will not be " \
    'auto-instrumented; flag-eval spans, manual instrumentation, logs and error capture are ' \
    'unaffected. This usually means an instrumentation gem dropped support for your framework ' \
    'version — upgrade the framework, or pin the instrumentation gem to a compatible release ' \
    '(e.g. gem "opentelemetry-instrumentation-rails", "~> 0.41").'
end

Instance Method Details

#add(severity, message = nil, progname = nil, &block) ⇒ Object



58
59
60
# File 'lib/launchdarkly_observability/instrumentation_log_filter.rb', line 58

def add(severity, message = nil, progname = nil, &block)
  forward?(message || progname || block&.call) ? @delegate.add(severity, message, progname, &block) : true
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/launchdarkly_observability/instrumentation_log_filter.rb', line 66

def respond_to_missing?(name, include_private = false)
  @delegate.respond_to?(name, include_private) || super
end