diff options
author | Yehuda Katz <wycats@gmail.com> | 2009-10-28 01:50:59 -0700 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2009-10-28 01:50:59 -0700 |
commit | 03d3824d965f38d3c595330d697fb16dc9efdb9a (patch) | |
tree | fb210c7d91ddab52b87cb18bef04ac2219eaa406 /activesupport/lib | |
parent | 654b33afc5a789aea90199bbb108093a80fe8020 (diff) | |
download | rails-03d3824d965f38d3c595330d697fb16dc9efdb9a.tar.gz rails-03d3824d965f38d3c595330d697fb16dc9efdb9a.tar.bz2 rails-03d3824d965f38d3c595330d697fb16dc9efdb9a.zip |
Make it possible to have IDs per request
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/notifications.rb | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 2cf91fc383..bf668964f5 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -45,7 +45,7 @@ module ActiveSupport mattr_accessor :queue class << self - delegate :instrument, :to => :instrumenter + delegate :instrument, :transaction_id, :generate_id, :to => :instrumenter def instrumenter Thread.current[:notifications_instrumeter] ||= Instrumenter.new(publisher) @@ -63,7 +63,18 @@ module ActiveSupport class Instrumenter def initialize(publisher) @publisher = publisher - @id = SecureRandom.hex(10) + @id = random_id + end + + def transaction + @id, old_id = random_id, @id + yield + ensure + @id = old_id + end + + def transaction_id + @id end def instrument(name, payload={}) @@ -72,6 +83,11 @@ module ActiveSupport ensure @publisher.publish(name, time, Time.now, result, @id, payload) end + + private + def random_id + SecureRandom.hex(10) + end end class Publisher |