活动支持::通知transaction_id



我一直在Github浏览Rails存储库以查找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

我只是深入研究了这一点,希望有某种方法可以从 LogSubscriber 中获取请求。 没有这样的运气。

Activesupport::Notifications::Instrumenter 有一个唯一的 ID,初始化时初始化为 SecureRandom.hex(10)。 此仪器器创建的任何 evernt 都会获得 10 位十六进制 ID。

在 ActiveSupport::Notifications 中,检测器是从 Thread.current 中挑选出来的,如果不存在,则创建检测器 - 因此在单个线程范围内发送的所有通知将具有相同的transaction_d,将它们统一在一起(这很好),但该transaction_id的初始值只是一个 10 位随机十六进制。(在 Activesupport::Notifications::Instrumenter#unique_id 中定义)

最新更新