Comments (12)
Hello, @alboyadjian. Thanks for bringing this issue to our attention - we will be investigating it and will follow up with you.
from newrelic-ruby-agent.
Hi, @alboyadjian. As we dig into this, it would be helpful to have some additional context from your logs.
Does your newrelic_agent.log include an error message that starts like this?
[2020-01-02 11:29:41 -0700 {hostname} (91275)] ERROR : Exception during Tracer...
from newrelic-ruby-agent.
Hi @rachelleahklein I didn't see this error in production (fortunately). It first appeared when running the test suite. I can try and produce a minimal app that allows reproducing the problem if that'd be helpful.
from newrelic-ruby-agent.
I haven't been able to reproduce it in a minimal fresh app, but when I comment out the rescue in the NewRelic::Agent::Tracer.start_datastore_segment, the following error gets raised:
NoMethodError: undefined method `attribute_filter' for nil:NilClass
gems/newrelic_rpm-6.8.0.360/lib/new_relic/agent/transaction/segment.rb:20:in `initialize'
gems/newrelic_rpm-6.8.0.360/lib/new_relic/agent/transaction/datastore_segment.rb:30:in `initialize'
gems/newrelic_rpm-6.8.0.360/lib/new_relic/agent/tracer.rb:308:in `new'
gems/newrelic_rpm-6.8.0.360/lib/new_relic/agent/tracer.rb:308:in `start_datastore_segment'
gems/newrelic_rpm-6.8.0.360/lib/new_relic/agent/datastores.rb:115:in `wrap'
The initialize of NewRelic::Agent::Transaction::Segment is calling
@attributes = Attributes.new(NewRelic::Agent.instance.attribute_filter)
so it looks like NewRelic::Agent.instance
is nil.
from newrelic-ruby-agent.
I was able to replicate it in a new, minimal app (a rails engine)
https://github.com/vhl/newrelic_gem_bug
from newrelic-ruby-agent.
First of all, thanks for your helpful reproduction!
The issue you're seeing doesn't stem from changes made to agent version 6.8.0, but rather, from the fact that, as you found out, there is no agent instance when this test runs. The agent must have been started for the NewRelic::Agent::Datastores.wrap
call to complete - which explains why you're seeing this failure only during tests.
I would recommend reworking your test to circumvent your with_newrelic_tracing
method, since I assume that's not the functionality you're interested in testing anyway. Please let us know if you would like ideas.
from newrelic-ruby-agent.
I don't think it's correct to say that the issue isn't from changes to the agent, for the following reasons:
- It wasn't failing in the old version, and changing versions is the only thing that makes the tests in the reproduction app start erroring.
- There aren't any breaking changes listed in the notes for this revision in the changelog, so this is seems to be an unexpected regression.
My guess is one of two things.
- The conditions under which an agent instance is automatically started have changed.
- Previously, the absence of a running agent didn't trigger these errors.
Reviewing the version diff: 6.7.0.359...6.8.0.360
It looks like this code should have prevented an agent from being started when running under rspec:
:'autostart.blacklisted_executables' => {
:default => 'irb,rspec',
A similar listing for blacklisted rake tasks also existed. I haven't yet verified under 6.7 whether the running agent is nil or not, but I'll try that next. My guess is that there'll be no agent instance under the old version as well, as the docs for NewRelic::Agent.manual_start seem to state that an agent will only be booted when running behind a web front-end that's not executing in test mode.
from newrelic-ruby-agent.
It looks like under 6.7.0.359, NewRelic::Agent.instance
is nil inside the initializer for NewRelic::Agent::Transaction::Segment so the first possible regression is ruled out.
- The conditions under which an agent instance is automatically started have changed.
Inspecting the code shows that the second regression seems to be the correct one:
- Previously, the absence of a running agent didn't trigger these errors.
Line 20 of the Segment class doesn't account for the absence of an Agent instance
@attributes = Attributes.new(NewRelic::Agent.instance.attribute_filter)
To maintain backwards compatibility, maybe a default set or empty set of Attributes could be used if NewRelic::Agent.instance is nil.
If it's not possible to provide backwards compatibility, then maybe a more informative error or warning message could be emitted if a nil NewRelic::Agent.instance is detected here, with details on how to manually start an agent if that's required in order to execute this code.
If it's impossible or inadvisable to start an agent when running unit tests, then I guess the only other solution is to stub the NewRelic calls in the test suite, which is what I'll do if you think that a backwards compatible-fix won't be provided.
Thanks for your attention on this.
from newrelic-ruby-agent.
Here's my stab at a basic fix: #310
from newrelic-ruby-agent.
Hi @alboyadjian,
Thanks for your response. I really appreciate your thoroughness in digging into this. I am not seeing the same results as you are when running this test with version 6.7.0 of the agent installed - the test still fails for me in your example app.
In either case, it's not expected for start_datastore_segment
to be invoked during a test, which is why it assumes an agent is running. Because this is not a usual use case, we don't plan to make any changes around this behavior in the agent at the moment.
However, it's not impossible to start an agent during a test. You could do so like this:
require 'new_relic/agent'
describe NewrelicGemBug::Queryable do
describe '#execute' do
it 'runs without failing' do
NewRelic::Agent.manual_start
NewrelicGemBug::Tab.create!(header: 'abc')
NewrelicGemBug::Queryable.new.execute.each do |record|
puts record.inspect
end
end
end
end
We would recommend either stubbing the method call that uses start_datastore_segment
or using this approach as a workaround.
Again, thank you for the time and thought you put into this discussion.
from newrelic-ruby-agent.
Ok. I'm not sure why you're getting different results than I am. See the screenshots below for results under 6.7 and 6.8.
However, thanks for the suggestions. We'll probably just stub the methods rather than starting an agent.
from newrelic-ruby-agent.
Hi @alboyadjian,
Weird! I'm not sure why we are getting different results. But I'm glad you will be able to resolve this in your test. Thanks again for your time digging into this.
from newrelic-ruby-agent.
Related Issues (20)
- FOSSA Ruby scanning - enhancements for our public repos HOT 2
- Add testing constraints for ffi HOT 1
- Revert `autostart_denylisted_constants` default change and document options HOT 1
- Spike: Investigate `autostart.denylisted_constants` HOT 1
- Investigate rspec-mocks incompatibility with `add_method_tracer` HOT 3
- Add a configuration option to permit custom method tracers to be defined automatically HOT 1
- CI: GHA - DRY up the action version shas HOT 1
- Meet OYC standards for Agent2Query service HOT 2
- Add Errors Inbox metadata configuration content to generated doc HOT 3
- [Spike] k8s & container integration HOT 1
- [Spike] Support FM/SA configuration HOT 1
- API driven noticed errors display as `expected: true`, and observed errors should too HOT 2
- Stripe integration Causes Cardinality Explosion HOT 6
- CI: address issues that stemmed from Rack hitting v3.1.x HOT 1
- CI: Investigate, address Grape v2.1 failures HOT 1
- Spike: Instrument `start_transaction.active_record` HOT 1
- Failed to get cluster name for elasticsearch during health check routine HOT 5
- Avoid deprecated Bundler method all_specs HOT 2
- Replace API key with access token in artifactory HOT 1
- [Spike] Agent2Query test definition discovery HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from newrelic-ruby-agent.