GithubHelp home page GithubHelp logo

Comments (12)

rachelleahklein avatar rachelleahklein commented on July 20, 2024

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.

rachelleahklein avatar rachelleahklein commented on July 20, 2024

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.

alboyadjian avatar alboyadjian commented on July 20, 2024

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.

alboyadjian avatar alboyadjian commented on July 20, 2024

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.

alboyadjian avatar alboyadjian commented on July 20, 2024

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.

rachelleahklein avatar rachelleahklein commented on July 20, 2024

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.

alboyadjian avatar alboyadjian commented on July 20, 2024

I don't think it's correct to say that the issue isn't from changes to the agent, for the following reasons:

  1. 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.
  2. 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.

  1. The conditions under which an agent instance is automatically started have changed.
  2. 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.

alboyadjian avatar alboyadjian commented on July 20, 2024

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.

  1. 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:

  1. 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.

alboyadjian avatar alboyadjian commented on July 20, 2024

Here's my stab at a basic fix: #310

from newrelic-ruby-agent.

rachelleahklein avatar rachelleahklein commented on July 20, 2024

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.

alboyadjian avatar alboyadjian commented on July 20, 2024

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.

Screen Shot 2020-01-07 at 9 23 44 AM
Screen Shot 2020-01-07 at 9 23 33 AM

from newrelic-ruby-agent.

rachelleahklein avatar rachelleahklein commented on July 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.