Giter VIP home page Giter VIP logo

newrelic-rake's Introduction

Newrelic::Rake

NewRelic instrument for rake task.

Installation

Add this line to your application's Gemfile:

gem 'newrelic-rake'

And then execute:

$ bundle

Or install it yourself as:

$ gem install newrelic-rake

Usage

There is usually nothing to do for rake tasks in rails that depend on :environment, monitoring of these should just work.

Rake files need to require newrelic-rake and start the newrelic agent before executing tasks to monitor:

require 'newrelic-rake'
NewRelic::Agent.manual_start

These steps happen automatically in Rails' :environment task if you use Bundler.require in your application.rb.

Install exit handler

In general, newrelic gem will automatically install exit handler. But if you have sinatra gem in Gemfile.lock, you have to manually install exit handler

at_exit { NewRelic::Agent.shutdown  }

Authors and Contributors

Contributors

Please fork and contribute, any help in making this project better is appreciated!

This project is a member of the OSS Manifesto.

Copyright

Copyright @ 2012 - 2013 Richard Huang. See MIT-LICENSE for details

newrelic-rake's People

Contributors

flyerhzm avatar spectator avatar jasonrclark avatar piotrze avatar wireframe avatar schnittchen avatar

Stargazers

Eric Zhang avatar Tim Sandquist avatar Kouichi Kay Ohshima avatar Miguel M. Almeida avatar Fabrizio Regini avatar Ronny Engelmann avatar Clint Plummer avatar 狼叔 avatar Andrey Ikonnikov avatar Alexey Mikhaylov avatar Nick Grandy avatar Cristian Molina avatar Igor Zubkov avatar David Collom avatar Jason Parraga avatar  avatar Guoqiang Li avatar Mathieu Ravaux avatar Justin Hileman avatar Ionatan Wiznia avatar Zac Siegel avatar Anderson Freitas avatar  avatar Vincent Glennon avatar Tomasz Szymczyszyn avatar Hiroshi SHIBATA avatar Nathan Esquenazi avatar Aaron Gibralter avatar Colin Schlueter avatar

Watchers

 avatar James Cloos avatar  avatar

newrelic-rake's Issues

Not seeing rake transactions in New Relic

Not sure if the directions aren't idiot proof enough but I have the gem running production but I don't see any transactions listed for my rake tasks. To make sure the agent and the gem were running I included the following within my rake tasks.

require 'newrelic-rake'
NewRelic::Agent.manual_start

Running rails 4.0.2

Don't see my rake task under background samples in New Relic thread profiling.

I'm running a separate environment where my rails codebase is being used exclusively for running rake tasks, not serving any requests. I've added newrelic-rake and am successfully able to see my rake tasks under Background Tasks in the New Relic dashboard.

However, if I run a New Relic Thread Profiler during a time when I have these rake tasks running, the result doesn't show any samples at all, particularly none for "background" which is where I would expect these to show up since that's where they show up in New Relic dashboard.

Is there any specific reason why this wouldn't be supported by newrelic-rake? I'm certainly going to investigate further myself but if you have any reason to think this is a bug/misconfiguration or just something that wouldn't work with current newrelic-rake I'd appreciate a pointer. Thanks!

StatsEngine#metrics usage in tests

Hey there! We noticed that the tests for your gem are using the StatsEngine#metrics method, which with version 3.11.0 of newrelic_rpm is going away.

Luckily, we've provided a replacement which is what we use internally for validating metric recording called assert_metrics_recorded. You can see more documentation for it at https://docs.newrelic.com/docs/agents/ruby-agent/frameworks/third-party-instrumentation#testing-your-extension.

Let us know if you have any problems with updating to use the new testing methods, and thanks for your work extending the Ruby agent! ✨

cc/ @tkrajcar

Can't add a scope listener midflight in a transaction

Currently when I run any rake task after adding newrelic-rake to my project, I'm seeing something similar to:

$ rake RAILS_ENV=production db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
** Invoke db:schema:dump (first_time)
** Invoke environment
rake aborted!
Can't add a scope listener midflight in a transaction
// followed by stack trace

I haven't had time yet to look at NewRelic internals so that's about all I can provide. Issue goes away as soon as I remove the gem. Going to jump into code now and see if there's something that can be done on the newrelic-rake end to mitigate this.

Respect autostart.blacklisted_rake_tasks setting

First of all, great gem, really useful!

My issue is that the autostart.blacklisted_rake_tasks setting causes newrelic_rpm not to start the Agent for certain rake tasks, which didn't play nicely with newrelic-rake for the "assets:precompile" task.

Full history:

I noticed some warnings after deploying to Heroku:

WARN : Error installing New Relic Browser Monitoring middleware
WARN : RuntimeError: can't modify frozen Array

Did some digging and discovered that it's due to:
config.middleware.use NewRelic::Rack::BrowserMonitoring

(from the newrelic_rpm gem)

Seems to be causing the error because the assets tasks do...

# Override this task change the loaded dependencies
desc "Load asset compile environment"
task :environment do
  # Load full Rails environment by default
  Rake::Task['environment'].invoke
end

(from the sprockets-rails gem)

For now, I've set agent_enabled: true which solves the issue, but ideally I could use the autostart.blacklisted_rake_tasks option (really I would just use the defaults) to avoid starting the Agent for assets tasks, and then the newrelic-rake gem would just "fall in line."

So, I think the main fix is to respect the autostart.blacklisted_rake_tasks setting, which contains "assets:precompile" by default.

Thoughts?

Setup needed for plain tasks

This gem works like a charm for rails projects and rake tasks with the :environment dependency. Other rake tasks don't appear in NR.

I analyzed this a bit and found out :environment tasks are caught because

  • people usually do Bundler.require in their application.rb
  • the newrelic_rpm gem has a railtie with an initializer starting the agent

These prerequisits amount roughly to this setup:

require 'newrelic-rake'
NewRelic::Agent.manual_start

Placing these lines in the rake file should make things work for all tasks.

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.