Skip to content

[BUG]: Constant resolution issue with rails runner and datadog 2.19.0 #4852

@jonswar

Description

@jonswar

Tracer Version(s)

2.19.0

Ruby Version(s)

ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin22]

Relevent Library and Version(s)

No response

Bug Report

After upgrading to Datadog 2.19.0, there's an issue with constant resolution when using rails runner to execute Ruby files. The issue occurs when a script tries to reference constants defined within a module namespace that were loaded during Rails initialization.

The issue appears to be related the patching of Kernel.load. If I comment out lines 78-110 of lib/datadog/tracing/contrib/rails/runner.rb, the bug goes away.

Reproduction Code

  1. Create a new Rails application:
rails new bug --minimal
  1. Add datadog 2.18.0 to the Gemfile:
gem 'datadog', '2.18.0'
  1. Create a file config/initializers/datadog.rb:
require 'datadog/tracing'

Datadog.configure do |c|
  c.tracing.instrument :rails
end
  1. Create a file config/initializers/example_module.rb:
module ExampleNamespace
  module Jobs
  end
end
  1. Create a file lib/tasks/example_task.rb:
module ExampleNamespace
  puts Jobs.name
end
  1. Run the task, it should print "ExampleNamespace::Jobs":
bundle exec rails runner lib/tasks/example_task.rb
  1. Upgrade to datadog 2.19.0 in Gemfile
gem 'datadog', '2.18.0'
  1. Run the task, it should fail:
bundle exec rails runner lib/tasks/example_task.rb

Configuration Block

See above

Error Logs

N/A

Operating System

Darwin Kernel Version 24.5.0 (but also repro'd on Linux)

How does Datadog help you?

No response

Metadata

Metadata

Assignees

No one assigned

    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