Skip to content

[BUG]: undefined method 'subdomain' for an instance of Rack::Request (NoMethodError) #4784

@pcothenet

Description

@pcothenet

Tracer Version(s)

2.18.0

Ruby Version(s)

ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM

Relevent Library and Version(s)

No response

Bug Report

In the past few days, we've had spikes of error requests in our application. Requests from bots (including DD Synthetics) are triggering trace errors on innocuous routes (/favicon, /wp-admin/).

nomethoderror: undefined method 'subdomain' for an instance of Rack::Request
/usr/local/bundle/ruby/3.4.0/gems/actionpack-8.0.2/lib/action_dispatch/journey/route.rb:153:in 'block in ActionDispatch::Journey::Route#matches?': undefined method 'subdomain' for an instance of Rack::Request (NoMethodError)
	from /usr/local/bundle/ruby/3.4.0/gems/actionpack-8.0.2/lib/action_dispatch/journey/route.rb:150:in 'Hash#each'
	from /usr/local/bundle/ruby/3.4.0/gems/actionpack-8.0.2/lib/action_dispatch/journey/route.rb:150:in 'Enumerable#all?'
	from /usr/local/bundle/ruby/3.4.0/gems/actionpack-8.0.2/lib/action_dispatch/journey/route.rb:150:in 'ActionDispatch::Journey::Route#matches?'
	from /usr/local/bundle/ruby/3.4.0/gems/actionpack-8.0.2/lib/action_dispatch/journey/router.rb:121:in 'block in ActionDispatch::Journey::Router#find_routes'
	from /usr/local/bundle/ruby/3.4.0/gems/actionpack-8.0.2/lib/action_dispatch/journey/router.rb:121:in 'Array#select!'
	from /usr/local/bundle/ruby/3.4.0/gems/actionpack-8.0.2/lib/action_dispatch/journey/router.rb:121:in 'ActionDispatch::Journey::Router#find_routes'
	from /usr/local/bundle/ruby/3.4.0/gems/datadog-2.18.0/lib/datadog/tracing/contrib/action_pack/action_dispatch/instrumentation.rb:67:in 'Datadog::Tracing::Contrib::ActionPack::ActionDispatch::Instrumentation::Journey::LazyRouter#find_routes'
	from /usr/local/bundle/ruby/3.4.0/gems/actionpack-8.0.2/lib/action_dispatch/journey/router.rb:69:in 'ActionDispatch::Journey::Router#recognize'
	from /usr/local/bundle/ruby/3.4.0/gems/datadog-2.18.0/lib/datadog/appsec/api_security/route_extractor.rb:50:in 'Datadog::AppSec::APISecurity::RouteExtractor.route_pattern'
	from /usr/local/bundle/ruby/3.4.0/gems/datadog-2.18.0/lib/datadog/appsec/api_security/sampler.rb:47:in 'Datadog::AppSec::APISecurity::Sampler#sample?'
	from /usr/local/bundle/ruby/3.4.0/gems/datadog-2.18.0/lib/datadog/appsec/api_security.rb:14:in 'Datadog::AppSec::APISecurity.sample?'
	from /usr/local/bundle/ruby/3.4.0/gems/datadog-2.18.0/lib/datadog/appsec/contrib/rack/request_middleware.rb:119:in 'Datadog::AppSec::Contrib::Rack::RequestMiddleware#call'
	from /usr/local/bundle/ruby/3.4.0/gems/datadog-2.18.0/lib/datadog/tracing/contrib/rack/middlewares.rb:70:in 'block in Datadog::Tracing::Contrib::Rack::TraceMiddleware#call'
	from /usr/local/bundle/ruby/3.4.0/gems/datadog-2.18.0/lib/datadog/tracing/contrib/rack/trace_proxy_middleware.rb:17:in 'Datadog::Tracing::Contrib::Rack::TraceProxyMiddleware.call'
	from /usr/local/bundle/ruby/3.4.0/gems/datadog-2.18.0/lib/datadog/tracing/contrib/rack/middlewares.rb:49:in 'Datadog::Tracing::Contrib::Rack::TraceMiddleware#call'
	from /usr/local/bundle/ruby/3.4.0/gems/actionpack-8.0.2/lib/action_dispatch/middleware/static.rb:27:in 'ActionDispatch::Static#call'
	from /usr/local/bundle/ruby/3.4.0/gems/railties-8.0.2/lib/rails/engine.rb:535:in 'Rails::Engine#call'
	from /usr/local/bundle/ruby/3.4.0/gems/puma-6.6.0/lib/puma/configuration.rb:279:in 'Puma::Configuration::ConfigMiddleware#call'
	from /usr/local/bundle/ruby/3.4.0/gems/puma-6.6.0/lib/puma/request.rb:99:in 'block in Puma::Request#handle_request'
	from /usr/local/bundle/ruby/3.4.0/gems/puma-6.6.0/lib/puma/thread_pool.rb:390:in 'Puma::ThreadPool#with_force_shutdown'
	from /usr/local/bundle/ruby/3.4.0/gems/puma-6.6.0/lib/puma/request.rb:98:in 'Puma::Request#handle_request'
	from /usr/local/bundle/ruby/3.4.0/gems/puma-6.6.0/lib/puma/server.rb:472:in 'Puma::Server#process_client'
	from /usr/local/bundle/ruby/3.4.0/gems/puma-6.6.0/lib/puma/server.rb:254:in 'block in Puma::Server#run'
	from /usr/local/bundle/ruby/3.4.0/gems/puma-6.6.0/lib/puma/thread_pool.rb:167:in 'block in Puma::ThreadPool#spawn_thread'

I threw the stack track at Claude and Claude Code (both using Opus 4), both think Datadog would be a possible culprit:

Datadog APM integration issue: The stack trace shows Datadog's APISecurity module trying to extract route patterns. It may be passing a raw Rack::Request instead of the expected ActionDispatch::Request to Rails' route matching logic.

I don't necessarily take that at face value, but our update of the gem (from 2.17.0 to 2.18.0) got deployed this morning, and this is when the errors started. Since that version also introduces Datadog::AppSec::APISecurity::RouteExtractor, it's not impossible the two are related.

Reproduction Code

No response

Configuration Block

No response

Error Logs

No response

Operating System

No response

How does Datadog help you?

No response

Metadata

Metadata

Assignees

Labels

bugInvolves a bugcommunityWas opened by a community member

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions