README.md in trace_location-0.1.1 vs README.md in trace_location-0.2.0

- old
+ new

@@ -19,77 +19,149 @@ $ gem install trace_location ## Usage You just surround the code which you want to track the process. -For example, when you want to track **the lifecycle of Rails application request/response**: +### Example 01. Track the lifecycle of Rails application + + ``` % bin/rails c -irb(main):001:0> env = Rack::MockRequest.env_for('http://localhost:3000/api/stories') +irb(main):001:0> env = Rack::MockRequest.env_for('http://localhost:3000/books') irb(main):002:0> TraceLocation.trace { status, headers, body = Rails.application.call(env) } -Created at /path/to/sampleapp/log/trace_location-2019050105051556706139.log +Created at /path/to/sampleapp/log/trace_location-2019050602051557077971.log => true ``` Then you can get a log like this: ``` -Logged by TraceLocation gem at 2019-05-01 05:22:19 -0500 +Logged by TraceLocation gem at 2019-05-06 02:39:31 +0900 https://github.com/yhirano55/trace_location [Tracing events] C: Call, R: Return -R <internal:prelude>:138#enable -C /vendor/bundle/gems/railties-5.2.3/lib/rails.rb:39#application -R /vendor/bundle/gems/railties-5.2.3/lib/rails.rb:41#application -C /vendor/bundle/gems/railties-5.2.3/lib/rails/engine.rb:522#call - C /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:607#build_request - C /vendor/bundle/gems/railties-5.2.3/lib/rails/engine.rb:705#build_request - C /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:247#env_config - R /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:275#env_config - C /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/request.rb:59#initialize - C /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:40#initialize - C /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/url.rb:186#initialize - C /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/filter_parameters.rb:34#initialize - R /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/filter_parameters.rb:39#initialize - R /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/url.rb:190#initialize - R /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:43#initialize - R /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/request.rb:67#initialize - C /vendor/bundle/gems/railties-5.2.3/lib/rails/engine.rb:534#routes - R /vendor/bundle/gems/railties-5.2.3/lib/rails/engine.rb:538#routes - C /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/request.rb:142#routes= - C /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:68#set_header - R /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:70#set_header - R /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/request.rb:144#routes= - C /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:129#script_name - C /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:52#get_header - R /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:54#get_header - R /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:129#script_name - C /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/request.rb:150#engine_script_name= - C /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/http/request.rb:138#routes - C /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:52#get_header - R /vendor/bundle/gems/rack-2.0.7/lib/rack/request.rb:54#get_header +C /vendor/bundle/gems/railties-5.2.3/lib/rails.rb:39 [Rails.application] +R /vendor/bundle/gems/railties-5.2.3/lib/rails.rb:41 [Rails.application] +C /vendor/bundle/gems/railties-5.2.3/lib/rails/engine.rb:522 [Rails::Engine#call] + C /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:607 [Rails::Application#build_request] + C /vendor/bundle/gems/railties-5.2.3/lib/rails/engine.rb:705 [Rails::Engine#build_request] + C /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:247 [Rails::Application#env_config] + C /vendor/bundle/gems/railties-5.2.3/lib/rails/engine.rb:528 [Rails::Engine#env_config] + R /vendor/bundle/gems/railties-5.2.3/lib/rails/engine.rb:530 [Rails::Engine#env_config] + C /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:372 [Rails::Application#config] + R /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:374 [Rails::Application#config] + C /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:372 [Rails::Application#config] + R /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:374 [Rails::Application#config] + C /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:394 [Rails::Application#secrets] + R /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:414 [Rails::Application#secrets] + C /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/ordered_options.rb:41 [ActiveSupport::OrderedOptions#method_missing] + C /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/ordered_options.rb:37 [ActiveSupport::OrderedOptions#[]] + R /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/ordered_options.rb:39 [ActiveSupport::OrderedOptions#[]] + R /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/ordered_options.rb:54 [ActiveSupport::OrderedOptions#method_missing] + C /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:428 [Rails::Application#secret_key_base] + C /vendor/bundle/gems/railties-5.2.3/lib/rails.rb:72 [Rails.env] + R /vendor/bundle/gems/railties-5.2.3/lib/rails.rb:74 [Rails.env] + C /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/string_inquirer.rb:26 [ActiveSupport::StringInquirer#method_missing] + R /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/string_inquirer.rb:32 [ActiveSupport::StringInquirer#method_missing] + C /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:394 [Rails::Application#secrets] + R /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:414 [Rails::Application#secrets] + C /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/ordered_options.rb:41 [ActiveSupport::OrderedOptions#method_missing] + C /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/ordered_options.rb:37 [ActiveSupport::OrderedOptions#[]] + R /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/ordered_options.rb:39 [ActiveSupport::OrderedOptions#[]] + R /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/ordered_options.rb:54 [ActiveSupport::OrderedOptions#method_missing] + R /vendor/bundle/gems/railties-5.2.3/lib/rails/application.rb:436 [Rails::Application#secret_key_base] .................. (an omission) .................. - R /vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/middleware/static.rb:128#call - C /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:9#respond_to? - C /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:9#respond_to? - C /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:9#respond_to? - C /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:9#respond_to? - C /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:9#respond_to? - R /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:15#respond_to? - R /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:15#respond_to? - R /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:15#respond_to? - R /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:15#respond_to? - R /vendor/bundle/gems/rack-2.0.7/lib/rack/body_proxy.rb:15#respond_to? - R /vendor/bundle/gems/rack-2.0.7/lib/rack/sendfile.rb:140#call - R /vendor/bundle/gems/railties-5.2.3/lib/rails/engine.rb:525#call +``` -Result: [200, {"Content-Type"=>"application/json; charset=utf-8", "ETag"=>"W/\"42334f8fba25471804e2cfa66fa989a7\"", "Cache-Control"=>"max-age=0, private, must-revalidate", "X-Request-Id"=>"f30153ff-3446-453a-a547-34c4b3766bfc", "X-Runtime"=>"0.455604"}, #<Rack::BodyProxy:0x00007f957960a430 @body=#<Rack::BodyProxy:0x00007f957f1c1f08 @body=#<Rack::BodyProxy:0x00007f957f1a8c10 @body=#<Rack::BodyProxy:0x00007f957f198040 @body=#<Rack::BodyProxy:0x00007f957f17bf58 @body=["[{\"id\":1,\"title\":\"The boy who cried 'wolf!'\",\"parentId\":1},{\"id\":2,\"title\":\"story 2\",\"parentId\":4},{\"id\":3,\"title\":\"story 3\",\"parentId\":null},{\"id\":4,\"title\":\"story 4\",\"parentId\":null},{\"id\":5,\"title\":\"story 1\",\"parentId\":null},{\"id\":6,\"title\":\"story 6\",\"parentId\":null},{\"id\":7,\"title\":\"story 7\",\"parentId\":null},{\"id\":8,\"title\":\"story 8\",\"parentId\":null},{\"id\":9,\"title\":\"story 9\",\"parentId\":null},{\"id\":10,\"title\":\"story 10\",\"parentId\":null},{\"id\":11,\"title\":\"story 11\",\"parentId\":null},{\"id\":12,\"title\":\"story 12\",\"parentId\":null},{\"id\":13,\"title\":\"story 13\",\"parentId\":null}]"], @block=#<Proc:0x00007f957f17ae78@/path/to/sampleapp/vendor/bundle/gems/rack-2.0.7/lib/rack/etag.rb:30>, @closed=false>, @block=#<Proc:0x00007f957f1a2d38@/path/to/sampleapp/vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/middleware/executor.rb:15>, @closed=false>, @block=#<Proc:0x00007f957f1b3728@/path/to/sampleapp/vendor/bundle/gems/railties-5.2.3/lib/rails/rack/logger.rb:39>, @closed=false>, @block=#<Proc:0x00007f957f1c07c0@/path/to/sampleapp/vendor/bundle/gems/activesupport-5.2.3/lib/active_support/cache/strategy/local_cache_middleware.rb:30>, @closed=false>, @block=#<Proc:0x00007f95796096c0@/path/to/sampleapp/vendor/bundle/gems/actionpack-5.2.3/lib/action_dispatch/middleware/executor.rb:15>, @closed=false>] +### Example 02. Track the validation process of Active Record + ``` +% bin/rails c +irb(main):001:0> book = Book.new(title: "My Book Title") +irb(main):002:0> TraceLocation.trace { book.validate } +Created at /path/to/sampleapp/log/trace_location-2019050104049576006131.log +=> true +``` + +Then you can get a log like this: + +``` +Logged by TraceLocation gem at 2019-05-06 02:44:29 +0900 +https://github.com/yhirano55/trace_location + +[Tracing events] C: Call, R: Return + +C /vendor/bundle/gems/activerecord-5.2.3/lib/active_record/validations.rb:65 [ActiveRecord::Validations#valid?] + C /vendor/bundle/gems/activerecord-5.2.3/lib/active_record/validations.rb:75 [ActiveRecord::Validations#default_validation_context] + C /vendor/bundle/gems/activerecord-5.2.3/lib/active_record/persistence.rb:231 [ActiveRecord::Persistence#new_record?] + C /vendor/bundle/gems/activerecord-5.2.3/lib/active_record/transactions.rb:490 [ActiveRecord::Transactions#sync_with_transaction_state] + C /vendor/bundle/gems/activerecord-5.2.3/lib/active_record/transactions.rb:494 [ActiveRecord::Transactions#update_attributes_from_transaction_state] + R /vendor/bundle/gems/activerecord-5.2.3/lib/active_record/transactions.rb:500 [ActiveRecord::Transactions#update_attributes_from_transaction_state] + R /vendor/bundle/gems/activerecord-5.2.3/lib/active_record/transactions.rb:492 [ActiveRecord::Transactions#sync_with_transaction_state] + R /vendor/bundle/gems/activerecord-5.2.3/lib/active_record/persistence.rb:234 [ActiveRecord::Persistence#new_record?] + R /vendor/bundle/gems/activerecord-5.2.3/lib/active_record/validations.rb:77 [ActiveRecord::Validations#default_validation_context] + C /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/validations.rb:336 [ActiveModel::Validations#valid?] + C /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/validations.rb:303 [ActiveModel::Validations#errors] + C /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:74 [ActiveModel::Errors#initialize] + C /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:470 [ActiveModel::Errors#apply_default_array] + R /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:473 [ActiveModel::Errors#apply_default_array] + C /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:470 [ActiveModel::Errors#apply_default_array] + R /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:473 [ActiveModel::Errors#apply_default_array] + R /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:78 [ActiveModel::Errors#initialize] + R /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/validations.rb:305 [ActiveModel::Validations#errors] + C /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:115 [ActiveModel::Errors#clear] + R /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:118 [ActiveModel::Errors#clear] + C /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/validations/callbacks.rb:117 [ActiveModel::Validations::Callbacks#run_validations!] + C /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:815 [ActiveRecord::Base#_run_validation_callbacks] + C /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:94 [ActiveSupport::Callbacks#run_callbacks] + C /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/core_ext/class/attribute.rb:124 [ActiveRecord::Base#__callbacks] + C /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/core_ext/class/attribute.rb:106 [ActiveRecord::Base.__callbacks] + R /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/core_ext/class/attribute.rb:128 [ActiveRecord::Base.__callbacks] + R /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:95 [ActiveRecord::Base#__callbacks] + C /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:539 [ActiveSupport::Callbacks::CallbackChain#empty?] + R /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:539 [ActiveSupport::Callbacks::CallbackChain#empty?] + C /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/validations.rb:408 [ActiveModel::Validations#run_validations!] + C /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:815 [ActiveRecord::Base#_run_validate_callbacks] + C /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:94 [ActiveSupport::Callbacks#run_callbacks] + C /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/core_ext/class/attribute.rb:124 [ActiveRecord::Base#__callbacks] + C /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/core_ext/class/attribute.rb:106 [ActiveRecord::Base.__callbacks] + R /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/core_ext/class/attribute.rb:128 [ActiveRecord::Base.__callbacks] + R /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:95 [ActiveRecord::Base#__callbacks] + C /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:539 [ActiveSupport::Callbacks::CallbackChain#empty?] + R /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:539 [ActiveSupport::Callbacks::CallbackChain#empty?] + R /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:139 [ActiveSupport::Callbacks#run_callbacks] + R /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:817 [ActiveRecord::Base#_run_validate_callbacks] + C /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/validations.rb:303 [ActiveModel::Validations#errors] + R /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/validations.rb:305 [ActiveModel::Validations#errors] + C /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:209 [ActiveModel::Errors#empty?] + C /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:179 [ActiveModel::Errors#size] + C /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:188 [ActiveModel::Errors#values] + R /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:192 [ActiveModel::Errors#values] + R /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:181 [ActiveModel::Errors#size] + R /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:211 [ActiveModel::Errors#empty?] + R /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/validations.rb:411 [ActiveModel::Validations#run_validations!] + R /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:139 [ActiveSupport::Callbacks#run_callbacks] + R /vendor/bundle/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:817 [ActiveRecord::Base#_run_validation_callbacks] + R /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/validations/callbacks.rb:119 [ActiveModel::Validations::Callbacks#run_validations!] + R /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/validations.rb:342 [ActiveModel::Validations#valid?] + C /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/validations.rb:303 [ActiveModel::Validations#errors] + R /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/validations.rb:305 [ActiveModel::Validations#errors] + C /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:209 [ActiveModel::Errors#empty?] + C /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:179 [ActiveModel::Errors#size] + C /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:188 [ActiveModel::Errors#values] + R /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:192 [ActiveModel::Errors#values] + R /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:181 [ActiveModel::Errors#size] + R /vendor/bundle/gems/activemodel-5.2.3/lib/active_model/errors.rb:211 [ActiveModel::Errors#empty?] +R /vendor/bundle/gems/activerecord-5.2.3/lib/active_record/validations.rb:69 [ActiveRecord::Validations#valid?] + +Result: true +``` + ## License -The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). +[MIT License](https://opensource.org/licenses/MIT)