pyroscope-ruby33 0.5.14-x86_64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/pyroscope.rb ADDED
@@ -0,0 +1,192 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'ffi'
5
+ require 'json'
6
+
7
+ module Pyroscope
8
+ module Rust
9
+ extend FFI::Library
10
+ ffi_lib File.expand_path(File.dirname(__FILE__)) + "/rbspy/rbspy.#{RbConfig::CONFIG["DLEXT"]}"
11
+ attach_function :initialize_logging, [:int], :bool
12
+ attach_function :initialize_agent, [:string, :string, :string, :string, :string, :int, :bool, :bool, :bool, :bool, :string, :string, :string, :string, :string], :bool
13
+ attach_function :add_thread_tag, [:uint64, :string, :string], :bool
14
+ attach_function :remove_thread_tag, [:uint64, :string, :string], :bool
15
+ attach_function :add_global_tag, [:string, :string], :bool
16
+ attach_function :remove_global_tag, [:string, :string], :bool
17
+ attach_function :drop_agent, [], :bool
18
+ end
19
+
20
+ module Utils
21
+ extend FFI::Library
22
+ ffi_lib File.expand_path(File.dirname(__FILE__)) + "/thread_id/thread_id.#{RbConfig::CONFIG["DLEXT"]}"
23
+ attach_function :thread_id, [], :uint64
24
+ end
25
+
26
+ if defined?(::Rails::Engine)
27
+ class Engine < ::Rails::Engine
28
+ config.after_initialize do
29
+ next unless ::Pyroscope.current_config && ::Pyroscope.current_config.autoinstrument_rails
30
+
31
+ ::Pyroscope.initialize_rails_hooks
32
+ end
33
+ end
34
+ end
35
+
36
+ Config = Struct.new(
37
+ :application_name,
38
+ :app_name,
39
+ :server_address,
40
+ :auth_token,
41
+ :basic_auth_username,
42
+ :basic_auth_password,
43
+ :log_level,
44
+ :sample_rate,
45
+ :detect_subprocesses,
46
+ :oncpu,
47
+ :report_pid,
48
+ :report_thread_id,
49
+ :tags,
50
+ :compression,
51
+ :report_encoding,
52
+ :autoinstrument_rails,
53
+ :tenant_id,
54
+ :http_headers,
55
+ ) do
56
+ def initialize(*)
57
+ super
58
+ # defaults:
59
+ self.application_name = ''
60
+ self.server_address = 'http://localhost:4040'
61
+ self.auth_token = ''
62
+ self.basic_auth_username = ''
63
+ self.basic_auth_password = ''
64
+ self.sample_rate = 100
65
+ self.detect_subprocesses = false
66
+ self.oncpu = true
67
+ self.report_pid = false
68
+ self.report_thread_id = false
69
+ self.log_level = 'error'
70
+ self.tags = {}
71
+ self.compression = 'gzip'
72
+ self.report_encoding = 'pprof'
73
+ self.autoinstrument_rails = true
74
+ self.tenant_id = ''
75
+ self.http_headers = {}
76
+ end
77
+ end
78
+
79
+ class << self
80
+ def current_config
81
+ @config
82
+ end
83
+
84
+ def configure
85
+ @config = Config.new
86
+
87
+ # Pass config to the block
88
+ yield @config
89
+
90
+ # Determine Logging level (kinda like an enum).
91
+ case @config.log_level
92
+ when 'trace'
93
+ @log_level = 10
94
+ when 'debug'
95
+ @log_level = 20
96
+ when 'info'
97
+ @log_level = 30
98
+ when 'warn'
99
+ @log_level = 40
100
+ when 'error'
101
+ @log_level = 50
102
+ else
103
+ @log_level = 50
104
+ end
105
+
106
+ Rust.initialize_logging(@log_level)
107
+
108
+ Rust.initialize_agent(
109
+ # these are defaults in case user-provided values are nil:
110
+ @config.app_name || @config.application_name || "",
111
+ @config.server_address || "",
112
+ @config.auth_token || "",
113
+ @config.basic_auth_username || "",
114
+ @config.basic_auth_password || "",
115
+ @config.sample_rate || 100,
116
+ @config.detect_subprocesses || false,
117
+ @config.oncpu || false,
118
+ @config.report_pid || false,
119
+ @config.report_thread_id || false,
120
+ tags_to_string(@config.tags || {}),
121
+ @config.compression || "",
122
+ @config.report_encoding || "pprof",
123
+ @config.tenant_id || "",
124
+ http_headers_to_json(@config.http_headers || {})
125
+ )
126
+ end
127
+
128
+ def initialize_rails_hooks
129
+ block = lambda do |ctrl, action|
130
+ Pyroscope.tag_wrapper({
131
+ "action" => "#{ctrl.controller_name}/#{ctrl.action_name}"
132
+ }, &action)
133
+ end
134
+
135
+ ActionController::API.__send__(:around_action, block) if defined? ActionController::API
136
+ ActionController::Base.__send__(:around_action, block) if defined? ActionController::Base
137
+ end
138
+
139
+ def tag_wrapper(tags)
140
+ tid = thread_id
141
+ _add_tags(tid, tags)
142
+ begin
143
+ yield
144
+ ensure
145
+ _remove_tags(tid, tags)
146
+ end
147
+ end
148
+
149
+ def tag(tags)
150
+ warn("deprecated. Use `Pyroscope.tag_wrapper` instead.")
151
+ end
152
+
153
+ def remove_tags(*tags)
154
+ warn("deprecated. Use `Pyroscope.tag_wrapper` instead.")
155
+ end
156
+
157
+ def thread_id
158
+ return Utils.thread_id
159
+ end
160
+
161
+ def _add_tags(thread_id, tags)
162
+ tags.each do |tag_name, tag_value|
163
+ Rust.add_thread_tag(thread_id, tag_name.to_s, tag_value.to_s)
164
+ end
165
+ end
166
+
167
+ def _remove_tags(thread_id, tags)
168
+ tags.each do |tag_name, tag_value|
169
+ Rust.remove_thread_tag(thread_id, tag_name.to_s, tag_value.to_s)
170
+ end
171
+ end
172
+
173
+ def stop
174
+ Rust.drop_agent
175
+ end
176
+
177
+ def shutdown
178
+ stop
179
+ end
180
+
181
+ private
182
+
183
+ def tags_to_string(tags)
184
+ tags.map { |k, v| "#{k}=#{v}" }.join(',')
185
+ end
186
+
187
+ def http_headers_to_json(http_headers)
188
+ JSON.dump(http_headers)
189
+ end
190
+
191
+ end
192
+ end
Binary file
Binary file
data/pyroscope.gemspec ADDED
@@ -0,0 +1,71 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ begin
5
+ require File.expand_path(File.join(File.dirname(__FILE__), "lib/pyroscope/version"))
6
+ rescue LoadError
7
+ puts "WARNING: Could not load Pyroscope::VERSION"
8
+ end
9
+
10
+ Gem::Specification.new do |s|
11
+ s.name = 'pyroscope-ruby33'
12
+ s.version = Pyroscope::VERSION
13
+ s.summary = 'Pyroscope'
14
+ s.description = 'Pyroscope FFI Integration for Ruby'
15
+ s.authors = ['Pyroscope Team']
16
+ s.email = ['contact@pyroscope.io']
17
+ s.homepage = 'https://pyroscope.io'
18
+ s.license = 'Apache-2.0'
19
+ s.metadata = {
20
+ "homepage_uri" => "https://pyroscope.io",
21
+ "bug_tracker_uri" => "https://github.com/pyroscope-io/pyroscope-rs/issues",
22
+ "documentation_uri" => "https://pyroscope.io/docs/ruby/",
23
+ "changelog_uri" => "https://github.com/pyroscope-io/pyroscope-rs/tree/main/pyroscope_ffi/ruby/CHANGELOG.md",
24
+ "source_code_uri" => "https://github.com/pyroscope-io/pyroscope-rs/tree/main/pyroscope_ffi/ruby",
25
+ }
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ #s.files = Dir.chdir(__dir__) do
30
+ #`git ls-files -z`.split("\x0").reject do |f|
31
+ #(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
32
+ #end
33
+ #end
34
+ # s.files = `git ls-files -z`.split("\0").reject { |f| f =~ /^(\.|G|spec|Rakefile)/ }
35
+ s.files = [
36
+ "Gemfile",
37
+ "Gemfile.lock",
38
+ "LICENSE",
39
+ # "Makefile",
40
+ "README.md",
41
+ # "Rakefile",
42
+ "ext/rbspy/Cargo.toml",
43
+ "ext/rbspy/Rakefile",
44
+ "ext/rbspy/build.rs",
45
+ "ext/rbspy/cbindgen.toml",
46
+ "ext/rbspy/extconf.rb",
47
+ "ext/rbspy/include/rbspy.h",
48
+ "ext/rbspy/src/lib.rs",
49
+ "ext/thread_id/Cargo.toml",
50
+ "ext/thread_id/Rakefile",
51
+ "ext/thread_id/build.rs",
52
+ "ext/thread_id/cbindgen.toml",
53
+ "ext/thread_id/extconf.rb",
54
+ "ext/thread_id/include/thread_id.h",
55
+ "ext/thread_id/src/lib.rs",
56
+ "lib/pyroscope.rb",
57
+ "lib/pyroscope/version.rb",
58
+ "pyroscope.gemspec",
59
+ # "scripts/tests/test.rb",
60
+ ]
61
+ s.platform = Gem::Platform::RUBY
62
+
63
+ s.required_ruby_version = ">= 1.9.3"
64
+
65
+ s.extensions = ['ext/rbspy/extconf.rb', 'ext/thread_id/extconf.rb']
66
+
67
+ s.add_dependency 'ffi'
68
+
69
+ s.add_development_dependency 'bundler'
70
+ s.add_development_dependency 'rake', '~> 13.0'
71
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pyroscope-ruby33
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.14
5
+ platform: x86_64-linux
6
+ authors:
7
+ - Pyroscope Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-01-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ force_ruby_platform: false
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '13.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '13.0'
56
+ description: Pyroscope FFI Integration for Ruby
57
+ email:
58
+ - contact@pyroscope.io
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE
66
+ - README.md
67
+ - ext/rbspy/Cargo.toml
68
+ - ext/rbspy/Rakefile
69
+ - ext/rbspy/build.rs
70
+ - ext/rbspy/cbindgen.toml
71
+ - ext/rbspy/extconf.rb
72
+ - ext/rbspy/include/rbspy.h
73
+ - ext/rbspy/src/lib.rs
74
+ - ext/thread_id/Cargo.toml
75
+ - ext/thread_id/Rakefile
76
+ - ext/thread_id/build.rs
77
+ - ext/thread_id/cbindgen.toml
78
+ - ext/thread_id/extconf.rb
79
+ - ext/thread_id/include/thread_id.h
80
+ - ext/thread_id/src/lib.rs
81
+ - lib/pyroscope.rb
82
+ - lib/pyroscope/version.rb
83
+ - lib/rbspy/rbspy.so
84
+ - lib/thread_id/thread_id.so
85
+ - pyroscope.gemspec
86
+ homepage: https://pyroscope.io
87
+ licenses:
88
+ - Apache-2.0
89
+ metadata:
90
+ homepage_uri: https://pyroscope.io
91
+ bug_tracker_uri: https://github.com/pyroscope-io/pyroscope-rs/issues
92
+ documentation_uri: https://pyroscope.io/docs/ruby/
93
+ changelog_uri: https://github.com/pyroscope-io/pyroscope-rs/tree/main/pyroscope_ffi/ruby/CHANGELOG.md
94
+ source_code_uri: https://github.com/pyroscope-io/pyroscope-rs/tree/main/pyroscope_ffi/ruby
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 1.9.3
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubygems_version: 3.5.22
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Pyroscope
114
+ test_files: []