gpt4 book ai didi

ruby-on-rails - ActiveSupport::Notifications transaction_id

转载 作者:行者123 更新时间:2023-12-01 01:14:25 24 4
gpt4 key购买 nike

我一直在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 中定义)

关于ruby-on-rails - ActiveSupport::Notifications transaction_id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12916482/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com