Module: Pyroscope
- Defined in:
- lib/pyroscope.rb,
lib/pyroscope/version.rb
Defined Under Namespace
Modules: Rust, Utils Classes: Config, Engine
Constant Summary collapse
- VERSION =
'0.6.7'.freeze
Class Method Summary collapse
- ._add_tags(thread_id, tags) ⇒ Object
- ._remove_tags(thread_id, tags) ⇒ Object
- .configure {|@config| ... } ⇒ Object
- .current_config ⇒ Object
- .initialize_rails_hooks ⇒ Object
- .remove_tags(*tags) ⇒ Object
- .shutdown ⇒ Object
- .stop ⇒ Object
- .tag(tags) ⇒ Object
- .tag_wrapper(tags) ⇒ Object
- .thread_id ⇒ Object
Class Method Details
._add_tags(thread_id, tags) ⇒ Object
161 162 163 164 165 |
# File 'lib/pyroscope.rb', line 161 def (thread_id, ) .each do |tag_name, tag_value| Rust.add_thread_tag(thread_id, tag_name.to_s, tag_value.to_s) end end |
._remove_tags(thread_id, tags) ⇒ Object
167 168 169 170 171 |
# File 'lib/pyroscope.rb', line 167 def (thread_id, ) .each do |tag_name, tag_value| Rust.remove_thread_tag(thread_id, tag_name.to_s, tag_value.to_s) end end |
.configure {|@config| ... } ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/pyroscope.rb', line 84 def configure @config = Config.new # Pass config to the block yield @config # Determine Logging level (kinda like an enum). case @config.log_level when 'trace' @log_level = 10 when 'debug' @log_level = 20 when 'info' @log_level = 30 when 'warn' @log_level = 40 when 'error' @log_level = 50 else @log_level = 50 end Rust.initialize_logging(@log_level) Rust.initialize_agent( # these are defaults in case user-provided values are nil: @config.app_name || @config.application_name || "", @config.server_address || "", @config.auth_token || "", @config.basic_auth_username || "", @config.basic_auth_password || "", @config.sample_rate || 100, @config.detect_subprocesses || false, @config.oncpu || false, @config.report_pid || false, @config.report_thread_id || false, (@config. || {}), @config.compression || "", @config.report_encoding || "pprof", @config.tenant_id || "", http_headers_to_json(@config.http_headers || {}) ) end |
.current_config ⇒ Object
80 81 82 |
# File 'lib/pyroscope.rb', line 80 def current_config @config end |
.initialize_rails_hooks ⇒ Object
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/pyroscope.rb', line 128 def initialize_rails_hooks block = lambda do |ctrl, action| Pyroscope.tag_wrapper({ "action" => "#{ctrl.controller_name}/#{ctrl.action_name}" }, &action) end ActionController::API.__send__(:around_action, block) if defined? ActionController::API ActionController::Base.__send__(:around_action, block) if defined? ActionController::Base end |
.remove_tags(*tags) ⇒ Object
153 154 155 |
# File 'lib/pyroscope.rb', line 153 def (*) warn("deprecated. Use `Pyroscope.tag_wrapper` instead.") end |
.shutdown ⇒ Object
177 178 179 |
# File 'lib/pyroscope.rb', line 177 def shutdown stop end |
.stop ⇒ Object
173 174 175 |
# File 'lib/pyroscope.rb', line 173 def stop Rust.drop_agent end |
.tag(tags) ⇒ Object
149 150 151 |
# File 'lib/pyroscope.rb', line 149 def tag() warn("deprecated. Use `Pyroscope.tag_wrapper` instead.") end |
.tag_wrapper(tags) ⇒ Object
139 140 141 142 143 144 145 146 147 |
# File 'lib/pyroscope.rb', line 139 def tag_wrapper() tid = thread_id (tid, ) begin yield ensure (tid, ) end end |
.thread_id ⇒ Object
157 158 159 |
# File 'lib/pyroscope.rb', line 157 def thread_id return Utils.thread_id end |