From 03d3824d965f38d3c595330d697fb16dc9efdb9a Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Wed, 28 Oct 2009 01:50:59 -0700 Subject: Make it possible to have IDs per request --- activesupport/lib/active_support/notifications.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support/notifications.rb') 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 -- cgit v1.2.3