Skip to content

Instantly share code, notes, and snippets.

View gnarg's full-sized avatar

Jon Guymon gnarg

  • New Relic
  • Portland, OR
View GitHub Profile
@gnarg
gnarg / end_transaction_with_thread_local_cleanup.rb
Created September 30, 2012 04:32
thread cleanup for webrick
module NewRelic::Agent::StatsEngine::Transactions
alias_method :end_transaction, :end_transaction_without_thread_local_cleanup
def end_transaction_with_thread_local_cleanup
end_transaction_without_thread_local_cleanup
Thread.current.keys.each do |key|
Thread.current[key] = nil
end
end
alias_method :end_transaction_with_thread_local_cleanup, :end_transaction
end
@gnarg
gnarg / bigdata.rb
Created September 14, 2012 23:37
jruby solution to histogram coding challenge
require 'thread'
class Chunk
def initialize(file, size, offset)
@handle = File.open(file)
@handle.pos = offset
@string = @handle.read(size)
if @string.index("\n") < @string.index(',')
look_back(4)
end
@gnarg
gnarg / 0.rb
Created June 22, 2012 20:10
Agent Instrumentation
defined?(ModuleToInstrument) && ModuleToInstrument.respond_to?(:method_to_decorate)
@gnarg
gnarg / test_agent.rb
Created June 15, 2012 20:33
ActiveSupport::Notifications instrumentation proof of concept
require 'new_relic/agent/transaction_info'
require 'new_relic/transaction_analysis'
require 'new_relic/transaction_sample'
require 'new_relic/control'
require 'new_relic/new_relic_service'
module NewRelic
class TestAgent
def initialize
@log = Logger.new('log/newrelic_agent.log')
@gnarg
gnarg / gist:2721792
Created May 17, 2012 21:53
Better error tracing for failed error tracing
module NewRelic
module Agent
class ErrorCollector
def notice_error(exception, options={})
return if should_exit_notice_error?(exception)
action_path = fetch_from_options(options, :metric, (NewRelic::Agent.instance.stats_engine.scope_name || ''))
exception_options = error_params_from_options(options).merge(exception_info(exception))
add_to_error_queue(NewRelic::NoticedError.new(action_path, exception_options, exception))
exception
rescue => e
@gnarg
gnarg / gist:2007867
Created March 9, 2012 18:19
Minimal instrumentation example
require "newrelic_noop/version"
require 'new_relic/agent/method_tracer'
module NewrelicNoop; end
Object.class_eval do
include NewRelic::Agent::MethodTracer
add_method_tracer :puts, 'Noop/puts'
end
@gnarg
gnarg / gist:1447814
Created December 8, 2011 17:53
possible tags
instrumentation
background_task
dj
resque
dispatcher
passenger
unicorn
framework
rails
sinatra
@gnarg
gnarg / gist:1389910
Created November 23, 2011 21:06
Initializer to bypass access to /proc fs
require 'new_relic/agent/sampler'
module NewRelic
module Agent
module Samplers
class MemorySampler < NewRelic::Agent::Sampler
def self.supported_on_this_platform?
false
end
end
@gnarg
gnarg / timmy!
Created October 24, 2011 23:44
timmy!
#!/usr/bin/env ruby
require 'yaml'
module Timmy
class Step
def self.set_priority(priority)
@priority = priority
end
@gnarg
gnarg / config.rb
Created October 19, 2011 20:58
rbx symbol lookup error
module Rubinius
BUILD_CONFIG = {
:which_ruby => :ruby,
:build_ruby => "/home/hudson/.rvm/rubies/ruby-1.8.7-p334/bin/ruby",
:build_rake => "rake",
:build_perl => "perl",
:llvm => :prebuilt,
:llvm_configure => "",
:cc => "gcc",
:cxx => "g++",