-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split agent startup for Rails into two initializers
The central argument around loading the agent before other initializers is to allow initializers to reference the add_method_tracer API. Including the modules before other initializers are run allows this to happen. If the second initializer doesn't specify when it should be run, it will run immediately after our first initializer. By specifying after: :load_config_initializers, the agent will not execute init_plugin until after initializers defined in config/initializers are run. This stops the agent from forcing ActiveRecord to load before customer-defined initializers.
- txn_name_debug_no_extra_service_logging
- txn_name_debug_logging_nethttp_chain
- txn_name_debug_logging_debug_failure
- txn_debug_logging
- thread_no_wrap
- thread_no_current_txn_if_finished
- thread_instrumentation_memory_bugfix
- thread_disable_tracing
- segment_limit_reset
- no_thread_txn_if_finished
- no_segment_no_txn3
- no_segment_no_txn2
- no_segment_no_txn
- iast_preview_release
- dup_fix_hash_iteration_issue
- debug_yml_not_loading
- browser_monitoring_attributes_extra_debug_msgs
- browser_monitoring_attributes_extra_debug_logs
- browser_monitoring_attributes_debug
- browser_monitoring_attributes_debug_logs
- 9.16.1
- 9.16.1-pre
- 9.16.0
- 9.16.0-pre
- 9.15.0
- 9.15.0-pre
- 9.14.0
- 9.14.0-pre
- 9.13.0
- 9.13.0-pre
- 9.12.0
- 9.12.0-pre
- 9.11.0
- 9.11.0-pre
- 9.10.2
- 9.10.2-pre
- 9.10.1
- 9.10.1-pre
- 9.10.0
- 9.10.0-pre
- 9.9.0
- 9.9.0-pre
- 9.8.0
- 9.8.0-pre
- 9.7.1
- 9.7.1-pre
- 9.7.0
- 9.7.0-pre
- 9.6.0
- 9.6.0-pre
- 9.5.0
- 9.5.0-pre
- 9.4.2
- 9.4.2-pre
- 9.4.1
- 9.4.1-pre
- 9.4.0
- 9.4.0-pre
- 9.3.1
- 9.3.1-pre
- 9.3.0
- 9.3.0-pre
- 9.2.2
- 9.2.2-pre
- 9.2.1
- 9.2.1-pre
- 9.2.0
- 9.2.0_no_threads
- 9.2.0-pre
- 9.1.0
- 9.1.0-pre
- 9.0.0
- 9.0.0-pre
- 8.16.0
- 8.16.0-pre2
- 8.16.0-pre
- 8.15.0
- 8.15.0-pre2
- 8.15.0-pre
- 8.14.0
- 8.14.0-pre
- 8t_span_events_off
- 8t_no_batching_and_no_compression
- 8t_no_batching_and_low_compression
- 8t_no_batching_and_high_compression
- 8t_batching_and_no_compression
- 8t_batching_and_compression_on
- 8t_batching_and_compression_off
- 8t_batching_and_compression_med
- 8t_batching_and_compression_low
1 parent
b5a3aed
commit 29e749d
Showing
13 changed files
with
258 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
require 'new_relic/agent/method_tracer' | ||
|
||
class Bloodhound < ActiveRecord::Base | ||
include ::NewRelic::Agent::MethodTracer | ||
|
||
def sniff | ||
puts "When a bloodhound sniffs a scent article (a piece of clothing or item touched only by the subject), " \ | ||
"air rushes through its nasal cavity and chemical vapors — or odors — lodge in the mucus and bombard the dog's " \ | ||
"scent receptors. " \ | ||
"Source: https://www.pbs.org/wnet/nature/underdogs-the-bloodhounds-amazing-sense-of-smell/350/" | ||
end | ||
|
||
add_method_tracer :sniff | ||
end | ||
|
||
Rails.application.config.active_record.timestamped_migrations = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
require 'new_relic/agent/method_tracer' | ||
|
||
class Bloodhound < ActiveRecord::Base | ||
include ::NewRelic::Agent::MethodTracer | ||
|
||
def sniff | ||
puts "When a bloodhound sniffs a scent article (a piece of clothing or item touched only by the subject)," \ | ||
"air rushes through its nasal cavity and chemical vapors — or odors — lodge in the mucus and bombard the dog's scent receptors. " \ | ||
"Source: https://www.pbs.org/wnet/nature/underdogs-the-bloodhounds-amazing-sense-of-smell/350/" | ||
end | ||
|
||
add_method_tracer :sniff | ||
end | ||
|
||
Rails.application.config.active_record.timestamped_migrations = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
require 'new_relic/agent/method_tracer' | ||
|
||
class Bloodhound < ActiveRecord::Base | ||
include ::NewRelic::Agent::MethodTracer | ||
|
||
def sniff | ||
puts "When a bloodhound sniffs a scent article (a piece of clothing or item touched only by the subject), " \ | ||
"air rushes through its nasal cavity and chemical vapors — or odors — lodge in the mucus and bombard the dog's " \ | ||
"scent receptors. " \ | ||
"Source: https://www.pbs.org/wnet/nature/underdogs-the-bloodhounds-amazing-sense-of-smell/350/" | ||
end | ||
|
||
add_method_tracer :sniff | ||
end | ||
|
||
Rails.application.config.active_record.timestamped_migrations = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
require 'new_relic/agent/method_tracer' | ||
|
||
class Bloodhound < ActiveRecord::Base | ||
include ::NewRelic::Agent::MethodTracer | ||
|
||
def sniff | ||
puts "When a bloodhound sniffs a scent article (a piece of clothing or item touched only by the subject), " \ | ||
"air rushes through its nasal cavity and chemical vapors — or odors — lodge in the mucus and bombard the dog's " \ | ||
"scent receptors. " \ | ||
"Source: https://www.pbs.org/wnet/nature/underdogs-the-bloodhounds-amazing-sense-of-smell/350/" | ||
end | ||
|
||
add_method_tracer :sniff | ||
end | ||
|
||
Rails.application.config.active_record.timestamped_migrations = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
require 'new_relic/agent/method_tracer' | ||
|
||
class Bloodhound < ActiveRecord::Base | ||
include ::NewRelic::Agent::MethodTracer | ||
|
||
def sniff | ||
puts "When a bloodhound sniffs a scent article (a piece of clothing or item touched only by the subject), " \ | ||
"air rushes through its nasal cavity and chemical vapors — or odors — lodge in the mucus and bombard the dog's " \ | ||
"scent receptors. " \ | ||
"Source: https://www.pbs.org/wnet/nature/underdogs-the-bloodhounds-amazing-sense-of-smell/350/" | ||
end | ||
|
||
add_method_tracer :sniff | ||
end | ||
|
||
Rails.application.config.active_record.timestamped_migrations = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
require 'new_relic/agent/method_tracer' | ||
|
||
class Bloodhound < ActiveRecord::Base | ||
include ::NewRelic::Agent::MethodTracer | ||
|
||
def sniff | ||
puts "When a bloodhound sniffs a scent article (a piece of clothing or item touched only by the subject), " \ | ||
"air rushes through its nasal cavity and chemical vapors — or odors — lodge in the mucus and bombard the dog's " \ | ||
"scent receptors. " \ | ||
"Source: https://www.pbs.org/wnet/nature/underdogs-the-bloodhounds-amazing-sense-of-smell/350/" | ||
end | ||
|
||
add_method_tracer :sniff | ||
end | ||
|
||
Rails.application.config.active_record.timestamped_migrations = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
require 'new_relic/agent/method_tracer' | ||
|
||
class Bloodhound < ActiveRecord::Base | ||
include ::NewRelic::Agent::MethodTracer | ||
|
||
def sniff | ||
puts "When a bloodhound sniffs a scent article (a piece of clothing or item touched only by the subject), " \ | ||
"air rushes through its nasal cavity and chemical vapors — or odors — lodge in the mucus and bombard the dog's " \ | ||
"scent receptors. " \ | ||
"Source: https://www.pbs.org/wnet/nature/underdogs-the-bloodhounds-amazing-sense-of-smell/350/" | ||
end | ||
|
||
add_method_tracer :sniff | ||
end | ||
|
||
Rails.application.config.active_record.timestamped_migrations = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
require 'new_relic/agent/method_tracer' | ||
|
||
class Bloodhound < ActiveRecord::Base | ||
include ::NewRelic::Agent::MethodTracer | ||
|
||
def sniff | ||
puts "When a bloodhound sniffs a scent article (a piece of clothing or item touched only by the subject), " \ | ||
"air rushes through its nasal cavity and chemical vapors — or odors — lodge in the mucus and bombard the dog's " \ | ||
"scent receptors. " \ | ||
"Source: https://www.pbs.org/wnet/nature/underdogs-the-bloodhounds-amazing-sense-of-smell/350/" | ||
end | ||
|
||
add_method_tracer :sniff | ||
end | ||
|
||
Rails.application.config.active_record.timestamped_migrations = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
require 'new_relic/agent/method_tracer' | ||
|
||
class Bloodhound < ActiveRecord::Base | ||
include ::NewRelic::Agent::MethodTracer | ||
|
||
def sniff | ||
puts "When a bloodhound sniffs a scent article (a piece of clothing or item touched only by the subject), " \ | ||
"air rushes through its nasal cavity and chemical vapors — or odors — lodge in the mucus and bombard the dog's " \ | ||
"scent receptors. " \ | ||
"Source: https://www.pbs.org/wnet/nature/underdogs-the-bloodhounds-amazing-sense-of-smell/350/" | ||
end | ||
|
||
add_method_tracer :sniff | ||
end | ||
|
||
Rails.application.config.active_record.timestamped_migrations = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
require 'new_relic/agent/method_tracer' | ||
|
||
class Bloodhound < ActiveRecord::Base | ||
include ::NewRelic::Agent::MethodTracer | ||
|
||
def sniff | ||
puts "When a bloodhound sniffs a scent article (a piece of clothing or item touched only by the subject), " \ | ||
"air rushes through its nasal cavity and chemical vapors — or odors — lodge in the mucus and bombard the dog's " \ | ||
"scent receptors. " \ | ||
"Source: https://www.pbs.org/wnet/nature/underdogs-the-bloodhounds-amazing-sense-of-smell/350/" | ||
end | ||
|
||
add_method_tracer :sniff | ||
end | ||
|
||
Rails.application.config.active_record.timestamped_migrations = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
require_relative '../test_helper' | ||
|
||
class NewRelicRpmTest < Minitest::Test | ||
# This test examines the behavior of an initializer when the agent is started in a Rails context | ||
# The initializer used for these tests is defined in test/environments/*/config/inititalizers/test.rb | ||
|
||
# We have documentation recommending customers call add_method_tracer | ||
# in their initializers, let's make sure this works | ||
def test_add_method_tracer_in_initializer_gets_traced | ||
skip unless defined?(Rails::VERSION) | ||
skip 'MySQL error for Rails 3.2' if Rails::VERSION::MAJOR == 3 | ||
|
||
assert Bloodhound.newrelic_method_exists?('sniff'), | ||
'Bloodhound#sniff not found by' \ | ||
'NewRelic::Agent::MethodTracer::ClassMethods::AddMethodTracer.newrelic_method_exists?' | ||
assert Bloodhound.method_traced?('sniff'), | ||
'Bloodhound#sniff not found by' \ | ||
'NewRelic::Agent::MethodTracer::ClassMethods::AddMethodTracer.method_traced?' | ||
end | ||
|
||
# All supported Rails versions have the default value for | ||
# timestamped_migrations as true. Our initializer sets it to false. | ||
# Test to resolve: https://github.com/newrelic/newrelic-ruby-agent/issues/662 | ||
def test_active_record_initializer_config_change_saved | ||
skip unless defined?(Rails::VERSION) | ||
# TODO: This test passes in a Rails console in a playground app and in the customer's environment | ||
# but fails in this unit test context | ||
skip if Gem::Version.new(NewRelic::VERSION::STRING) >= Gem::Version.new('8.13.0') | ||
skip 'MySQL error for Rails 3.2' if Rails::VERSION::MAJOR == 3 | ||
|
||
# Verify the configuration value was set to the initializer value | ||
refute Rails.application.config.active_record.timestamped_migrations, | ||
"Rails.application.config.active_record.timestamped_migrations equals true, expected false" | ||
|
||
# Verify the configuration value was applied to the ActiveRecord class variable | ||
if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('7.1') | ||
refute ActiveRecord.timestamped_migrations, "ActiveRecord.timestamped_migrations equals true, expected false" | ||
else | ||
refute ActiveRecord::Base.timestamped_migrations, | ||
"ActiveRecord::Base.timestamped_migrations equals true, expected false" | ||
end | ||
end | ||
end |