ActiveSupport :: Transaction_id Notifications

I looked through the Rails repository on Github to find the definition of transaction_id, but was unsuccessful.

What kind of deal is this? It seems that the same transaction_id is used for a group of events.

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

Result:

 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} 

Same transaction_id: 9eb707034598e4cc7c32

+4
source share
1 answer

I just dive deeply into this, hoping there is some way to get the request from LogSubscriber. There is no such luck.

Activesupport :: Notifications :: Instrumenter has a unique identifier initialized as SecureRandom.hex (10) when it is initialized. Any evernt created by this device receives a ten-digit hexadecimal identifier.

In ActiveSupport :: Notifications, the toolkit is selected from Thread.current and created if it is not there, so all notifications sent within the same thread will have the same transaction_d, combining them all together (which is nice), but the initial value of this transaction_id is just a 10 digit random hex. (defined in Activesupport :: Notifications :: Instrumenter # unique_id)

+3
source

Source: https://habr.com/ru/post/1440059/


All Articles