Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make it possible to have IDs per request

  • Loading branch information...
commit 03d3824d965f38d3c595330d697fb16dc9efdb9a 1 parent 654b33a
@wycats wycats authored
Showing with 18 additions and 2 deletions.
  1. +18 −2 activesupport/lib/active_support/notifications.rb
View
20 activesupport/lib/active_support/notifications.rb
@@ -45,7 +45,7 @@ module Notifications
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 @@ def subscribe(pattern=nil, &block)
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 @@ def instrument(name, payload={})
ensure
@publisher.publish(name, time, Time.now, result, @id, payload)
end
+
+ private
+ def random_id
+ SecureRandom.hex(10)
+ end
end
class Publisher
Please sign in to comment.
Something went wrong with that request. Please try again.