Finally Figured Out New Relic and JRuby
Monday, November 5th, 2012This afternoon, I decided to dig into the New Relic Ruby API and see if I couldn't figure out the problem that's been bugging me for a while. Basically, it's all about putting New Relic in a jruby-1.7.0 jar and getting the instrumentation to load.
I knew that New Relic had their code on GitHub, so I went and forked the code in hopes of fixing the problem.
I started digging in the first place I've come to suspect in jruby-1.7.0 - Dir.glob.
Sure enough, they had code that was using this in much the same way that the Configulations gem was: it was scanning directories, in this case, their own code, and loading the scripts it found. These scripts, it turns out, are their "instrumentation" directory.
Makes perfect sense.
The call to Dir.glob returned the empty array, so there was no error. But there was also nothing loaded. Simple. I changed the code from:
def load_instrumentation_files pattern Dir.glob(pattern) do |file| begin log.debug "Processing instrumentation file '#{file}'" require file.to_s
to:
def load_instrumentation_files pattern Dir.glob(pattern.gsub(/^jar:/, '')) do |file| begin log.debug "Processing instrumentation file '#{file}'" require file.to_s
and, as expected, everything started to work just fine!
I sent in a pull request to the New Relic folks so that they could fix their code, and I also sent them an email, as I was back talking to their support guys.
Got a nice note back from one of the support guys thanking me for the fix. I know jruby will get it fixed eventually, but this is really an issue that needs fixing sooner than later.
Maybe I'll fork that and fix it? 🙂