2012-10-16 46 views
4

我一直在瀏覽Github上的Rails存儲庫以查找transaction_id的定義,但不成功。ActiveSupport :: Notifications transaction_id

它是什麼樣的交易?它看起來像一組事件使用相同的transaction_id。

ActiveSupport::Notifications.subscribe do |name, start, finish, transaction_id , payload| 
    Rails.logger.debug(["notification:", name, start, finish, transaction_id , payload].join(" ")) 
end 

結果:

Started GET "/" for 127.0.0.1 at 2012-10-16 15:51:40 +0200 

notification: sql.active_record 2012-10-16 15:51:40 +0200 2012-10-16 15:51:40 +0200 9eb707034598e4cc7c32 {:sql=>"SHOW client_min_messages", :name=>"SCHEMA", :connection_id=>46235640, :binds=>[]} 

notification: sql.active_record 2012-10-16 15:51:40 +0200 2012-10-16 15:51:40 +0200 9eb707034598e4cc7c32 {:sql=>"SET client_min_messages TO 'panic'", :name=>"SCHEMA", :connection_id=>46235640, :binds=>[]} 

notification: sql.active_record 2012-10-16 15:51:40 +0200 2012-10-16 15:51:40 +0200 9eb707034598e4cc7c32 {:sql=>"SET standard_conforming_strings = on", :name=>"SCHEMA", :connection_id=>46235640, :binds=>[]} 

notification: sql.active_record 2012-10-16 15:51:40 +0200 2012-10-16 15:51:40 +0200 9eb707034598e4cc7c32 {:sql=>"SET client_min_messages TO 'notice'", :name=>"SCHEMA", :connection_id=>46235640, :binds=>[]} 

notification: sql.active_record 2012-10-16 15:51:40 +0200 2012-10-16 15:51:40 +0200 9eb707034598e4cc7c32 {:sql=>"SET time zone 'UTC'", :name=>"SCHEMA", :connection_id=>46235640, :binds=>[]} 

... 

notification: process_action.action_controller 2012-10-16 15:51:40 +0200 2012-10-16 15:51:41 +0200 9eb707034598e4cc7c32 {:controller=>"PagesController", :action=>"index", :params=>{"controller"=>"pages", "action"=>"index"}, :format=>:html, :method=>"GET", :path=>"/", :status=>200, :view_runtime=>339.344333, :db_runtime=>31.421587} 

同樣TRANSACTION_ID:9eb707034598e4cc7c32

回答

3

我只鴿子深入到這一點,希望有某種方式從LogSubscriber內獲得請求。沒有這樣的運氣。

Activesupport :: Notifications :: Instrumenter有一個唯一的ID,在初始化時初始化爲SecureRandom.hex(10)。任何由此儀器創建的天使都可以獲得這個10位十六進制ID。

在ActiveSupport :: Notifications中,Instrumenter是從Thread.current中挑選出來的,如果不存在則創建 - 因此,在單個線程範圍內發送的所有通知將具有相同的transaction_d,將它們統一在一起(即不錯),但該transaction_id的初始值只是一個10位數的隨機十六進制。 (在Activesupport :: Notifications :: Instrumenter#unique_id中定義)

相關問題