pyroscope 0.5.0-x86_64-darwin → 0.5.1-x86_64-darwin

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: 9cbeb9dcf8fc529aed335f7d5f94439c67a8fa49b3ff8a8746cf5aadbc7bb543
4
- data.tar.gz: b6491f129c7cbb4410dad521b7acbe9c7295f0c712e80a8405a841e702e8530b
3
+ metadata.gz: 9cb87b3d680d036992d9e4dc5c24623005acfc2025ec4578b3d87f62af60eef1
4
+ data.tar.gz: bf83c8dd6257c99e2a9e6bb288a446bbbddbc3b322ab4fed8a81b7a9422bf54f
5
5
  SHA512:
6
- metadata.gz: b89cfb96c15042be8d5d13f91caf8ddfe7210a00e44a3c4d27a04ac9bb9d814b0f8e72bd8daceaaff08431826748de27f6d11d75668ff2b3a497ada0cf51e6f8
7
- data.tar.gz: 428caa044a687356eb5332acbbd5aa79c6f6d05df1711086fd546f313c6e7d597c89cdf7480e02efdcd9a5e559654318870a56b2516a10581cb7789af8b563fa
6
+ metadata.gz: 78b08c983b3e61158df1a9b8cf80ae79c4f947d10d6b868bf9f8d8c600f1d2c6112783ebe0b2d7c3412bc731fdb0a121170c2abc73981337e1487d2ccbe7c603
7
+ data.tar.gz: df6ea2ce9a7aeea50718f47ed8feada39324fea35e56bcfd59608d673832ea825077bcc793fee507cb7edf641dd9e272e71e91554a7f52807aacce58e099fd5d
@@ -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
Binary file
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: x86_64-darwin
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