Skip to content

Instantly share code, notes, and snippets.

@mikecarroll
Created December 9, 2025 18:43
Show Gist options
  • Select an option

  • Save mikecarroll/97b116feb7e1522762372d58eb4fb70a to your computer and use it in GitHub Desktop.

Select an option

Save mikecarroll/97b116feb7e1522762372d58eb4fb70a to your computer and use it in GitHub Desktop.
Datadog / Coolhand stack level test
#!/usr/bin/env ruby
# Test with Rack environment to see if that changes the Datadog behavior
puts "πŸ§ͺ Testing with Rack environment simulation..."
# Simulate a Rack environment like what would exist during a web request
ENV['RACK_ENV'] = 'production'
require 'rack'
require 'faraday'
# Load and configure Datadog with Rack present
require 'datadog'
Datadog.configure do |c|
c.tracing.instrument :faraday
c.tracing.instrument :rack # Add Rack instrumentation
c.service = 'test-app'
c.env = 'production'
c.tracing.enabled = true
c.tracing.sampling.default_rate = 1.0
end
puts "βœ… Datadog configured with Rack instrumentation"
# Now load Coolhand
require 'coolhand/ruby'
Coolhand.configure do |config|
config.api_key = 'test-key'
config.silent = false
config.intercept_addresses = ["api.anthropic.com"]
end
puts "βœ… Coolhand configured"
# Check middleware on default connection
puts "\nπŸ” Checking default Faraday connection middleware:"
default_conn = Faraday.default_connection
puts " Handlers: #{default_conn.builder.handlers.map(&:klass)}"
puts "\nπŸ”₯ Testing new connection creation (like in background jobs)..."
begin
# This simulates what happens in a background job when making an API call
conn = Faraday.new('https://api.anthropic.com') do |f|
f.request :url_encoded
f.adapter :net_http
end
puts "βœ… SUCCESS: New connection created"
puts " New connection handlers: #{conn.builder.handlers.map(&:klass)}"
# Try making an actual request to see if middleware conflicts
puts "\n🌐 Testing actual HTTP request..."
response = conn.get('/status/200') rescue nil
puts "βœ… Request completed (or failed safely)"
rescue SystemStackError => e
puts "πŸ’₯ STACK OVERFLOW: #{e.message}"
puts " This is the conflict we're looking for!"
exit 1
rescue => e
puts "❌ Other error: #{e.class}: #{e.message}"
end
puts "\nπŸŽ‰ Test completed - no stack overflow with Rack environment"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment