pyroscope 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c54d01d273a289584bf1ecd0f69c7349e775f3e8a8b0a07a71a78095b4bbc78c
4
- data.tar.gz: ef6dfa8b2da02bcfdd17d8a6d49cd86cfe7666615bcbb690bd04459c0300599d
3
+ metadata.gz: df36b61e5b8fde45ebc360aedc8e109e3d37c7817d539721a48c00f59f1f66bc
4
+ data.tar.gz: 9bdb35db6a01df630a489716caee628d67c52984391d867b1f2693e5f137b85a
5
5
  SHA512:
6
- metadata.gz: c45a42bff9b659125547281a11a9623ef12469a91b61444a178d7895482a3889a6ed687f650cde9bb7bdfdaee163f5c1fa8a905e254116ad50ec6ece06f983d8
7
- data.tar.gz: '0108e948e4d9bf98a729b5628fe6d243d849e7d7721463b8f5623629330d8ebbbaa1cc95dbddd5966ab0849409ca9858240414169d69182a7dbc92e583ebb6dd'
6
+ metadata.gz: 816ece1b66998b8e128ab8e7fd8a625c5ea37d941fefd4f5025b5cb06fb8a2fa5dd27bd8ab0dca0ab5473818ae315c9e749edb7e5d126e524a80ae56917df802
7
+ data.tar.gz: 468ef393fa6008d5f63d49554820be41b307c59b0d414f712e96da677a51c66880cbcf01b751b24f80a0913d0e9f5c9e174d0f3561717c9d11ae5db90d269198
@@ -1,3 +1,3 @@
1
1
  module Pyroscope
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.5.1'.freeze
3
3
  end
data/lib/pyroscope.rb CHANGED
@@ -22,7 +22,32 @@ module Pyroscope
22
22
  attach_function :thread_id, [], :uint64
23
23
  end
24
24
 
25
- Config = Struct.new(:application_name, :app_name, :server_address, :auth_token, :log_level, :sample_rate, :detect_subprocesses, :oncpu, :report_pid, :report_thread_id, :tags, :compression, :report_encoding) do
25
+ if defined?(::Rails::Engine)
26
+ class Engine < ::Rails::Engine
27
+ config.after_initialize do
28
+ next unless ::Pyroscope.current_config && ::Pyroscope.current_config.autoinstrument_rails
29
+
30
+ ::Pyroscope.initialize_rails_hooks
31
+ end
32
+ end
33
+ end
34
+
35
+ Config = Struct.new(
36
+ :application_name,
37
+ :app_name,
38
+ :server_address,
39
+ :auth_token,
40
+ :log_level,
41
+ :sample_rate,
42
+ :detect_subprocesses,
43
+ :oncpu,
44
+ :report_pid,
45
+ :report_thread_id,
46
+ :tags,
47
+ :compression,
48
+ :report_encoding,
49
+ :autoinstrument_rails,
50
+ ) do
26
51
  def initialize(*)
27
52
  super
28
53
  # defaults:
@@ -38,10 +63,15 @@ module Pyroscope
38
63
  self.tags = {}
39
64
  self.compression = 'gzip'
40
65
  self.report_encoding = 'pprof'
66
+ self.autoinstrument_rails = true
41
67
  end
42
68
  end
43
69
 
44
70
  class << self
71
+ def current_config
72
+ @config
73
+ end
74
+
45
75
  def configure
46
76
  @config = Config.new
47
77
 
@@ -64,11 +94,8 @@ module Pyroscope
64
94
  @log_level = 50
65
95
  end
66
96
 
67
- # Initialize Logging
68
97
  Rust.initialize_logging(@log_level)
69
98
 
70
-
71
- # initialize Pyroscope Agent
72
99
  Rust.initialize_agent(
73
100
  # these are defaults in case user-provided values are nil:
74
101
  @config.app_name || @config.application_name || "",
@@ -85,6 +112,17 @@ module Pyroscope
85
112
  )
86
113
  end
87
114
 
115
+ def initialize_rails_hooks
116
+ block = lambda do |ctrl, action|
117
+ Pyroscope.tag_wrapper({
118
+ "action" => "#{ctrl.controller_name}/#{ctrl.action_name}"
119
+ }, &action)
120
+ end
121
+
122
+ ActionController::API.__send__(:around_action, block) if defined? ActionController::API
123
+ ActionController::Base.__send__(:around_action, block) if defined? ActionController::Base
124
+ end
125
+
88
126
  def tag_wrapper(tags)
89
127
  tid = thread_id
90
128
  _add_tags(tid, tags)
@@ -103,32 +141,34 @@ module Pyroscope
103
141
  warn("deprecated. Use `Pyroscope.tag_wrapper` instead.")
104
142
  end
105
143
 
106
- # convert tags object to string
107
- def tags_to_string(tags)
108
- tags.map { |k, v| "#{k}=#{v}" }.join(',')
109
- end
110
-
111
- # get thread id
112
144
  def thread_id
113
145
  return Utils.thread_id
114
146
  end
115
147
 
116
- # add tags
117
148
  def _add_tags(thread_id, tags)
118
149
  tags.each do |tag_name, tag_value|
119
150
  Rust.add_thread_tag(thread_id, tag_name.to_s, tag_value.to_s)
120
151
  end
121
152
  end
122
153
 
123
- # remove tags
124
154
  def _remove_tags(thread_id, tags)
125
155
  tags.each do |tag_name, tag_value|
126
156
  Rust.remove_thread_tag(thread_id, tag_name.to_s, tag_value.to_s)
127
157
  end
128
158
  end
129
159
 
130
- def shutdown
160
+ def stop
131
161
  Rust.drop_agent
132
162
  end
163
+
164
+ def shutdown
165
+ stop
166
+ end
167
+
168
+ private
169
+
170
+ def tags_to_string(tags)
171
+ tags.map { |k, v| "#{k}=#{v}" }.join(',')
172
+ end
133
173
  end
134
174
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pyroscope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pyroscope Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-06 00:00:00.000000000 Z
11
+ date: 2022-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi