Module: Apidepth

Defined in:
lib/apidepth/event.rb,
lib/apidepth.rb,
lib/apidepth/railtie.rb,
lib/apidepth/version.rb,
lib/apidepth/cli/setup.rb,
lib/apidepth/collector.rb,
lib/apidepth/cli/test_cmd.rb,
lib/apidepth/configuration.rb,
lib/apidepth/registry_loader.rb,
lib/apidepth/vendor_registry.rb,
lib/apidepth/rate_limit_headers.rb,
lib/apidepth/model_name_extractor.rb,
lib/apidepth/cli/framework_detector.rb,
lib/apidepth/net_http_instrumentation.rb

Overview

lib/apidepth/net_http_instrumentation.rb

Defined Under Namespace

Modules: CLI, Event, ModelNameExtractor, NetHTTPInstrumentation, RateLimitHeaders, VendorRegistry Classes: Collector, Configuration, Railtie, RegistryLoader

Constant Summary collapse

VERSION =
"0.5.0".freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject



30
31
32
# File 'lib/apidepth.rb', line 30

def logger
  @logger ||= Logger.new($stdout)
end

Class Method Details

.configurationObject



38
39
40
# File 'lib/apidepth.rb', line 38

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



34
35
36
# File 'lib/apidepth.rb', line 34

def configure
  yield(configuration)
end

.detect_app_serverObject



56
57
58
59
60
61
62
# File 'lib/apidepth.rb', line 56

def detect_app_server
  return "puma"      if defined?(Puma)
  return "unicorn"   if defined?(Unicorn)
  return "passenger" if defined?(PhusionPassenger)

  "unknown"
end

.sanitize_log(str) ⇒ Object

Strips line-break characters from untrusted strings before they reach log output. Prevents log injection (CVE-2025-27111 class of attack).



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

def sanitize_log(str)
  str.to_s.gsub(/[\r\n\t]/, " ").slice(0, 200)
end

.sdk_metadataObject

Computed once and frozen. Included in every batch payload so the collector can correlate data quality issues with specific SDK versions, Ruby runtimes, and app servers without needing the customer to file a support ticket.



45
46
47
48
49
50
51
52
53
54
# File 'lib/apidepth.rb', line 45

def 
  @sdk_metadata ||= {
    name: "apidepth-ruby",
    version: VERSION,
    ruby_version: RUBY_VERSION,
    ruby_platform: RUBY_PLATFORM,
    rails_version: (defined?(Rails) ? Rails.version : nil),
    app_server: detect_app_server
  }.compact.freeze
end