Skip to content

Instantly share code, notes, and snippets.

@mdub
Created July 26, 2011 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdub/1106667 to your computer and use it in GitHub Desktop.
Save mdub/1106667 to your computer and use it in GitHub Desktop.
Patch the NewRelic RPM agent to allow for use of Fibers
require 'new_relic/control'
# monkey-patch NewRelic::Agent::TransactionSampler to avoid storing the
# current TransactionSampleBuilder in a Thread-local, as it does not play nicely
# in the presence of Fibers
module NewRelic
module Agent
class TransactionSampler
ACTIVE_BUILDERS = {}
# Checks to see if the transaction sampler is disabled, if
# transaction trace recording is disabled by a thread local, or
# if execution is untraced - if so it clears the transaction
# sample builder from the thread local, otherwise it generates a
# new transaction sample builder with the stated time as a
# starting point and saves it in the thread local variable
def start_builder(time=nil)
if disabled || !NewRelic::Agent.is_transaction_traced? || !NewRelic::Agent.is_execution_traced?
clear_builder
else
ACTIVE_BUILDERS[Thread::current] ||= TransactionSampleBuilder.new(time)
end
end
# The current thread-local transaction sample builder
def builder
ACTIVE_BUILDERS[Thread::current]
end
# Sets the thread local variable storing the transaction sample
# builder to nil to clear it
def clear_builder
ACTIVE_BUILDERS[Thread::current] = nil
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment