infield 0.2.0 → 0.4.0
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.
- checksums.yaml +4 -4
- data/README.md +2 -6
- data/lib/infield/core_ext.rb +20 -1
- data/lib/infield/deprecation_warning.rb +17 -11
- data/lib/infield/heartbeat.rb +0 -1
- data/lib/infield/rails.rb +13 -2
- data/lib/infield/version.rb +1 -1
- data/lib/infield.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcc989dc4411ecacc35b71a9f831b51c7a985e550872393e68cbed78530b33cd
|
4
|
+
data.tar.gz: 9e681a218059596455a77728f371e30a016810eb3aaf608a6c0af8aa3236a9b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c361f23afc866c66338b633a7aefcf0714a0e4ec2ef5f8cccf568105751379207840eca47224ab1bf2339c16fa53e7038536ff97fba6822db9a5ed35622b57b5
|
7
|
+
data.tar.gz: 8010fcb20eb0c8f1168c1405f6f37f6e1cf8f6aaad08053cbffa493b0e43f8989f0aef0de1082f5377f9cbec823308f8672fc3cf291a37dcb155e79033b740e5
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ This gem handles reporting deprecation warnings to Infield from a Rails app.
|
|
4
4
|
|
5
5
|
## Setup
|
6
6
|
|
7
|
-
You'll need an API key and repo environment ID to use this gem.
|
7
|
+
You'll need an API key and repo environment ID to use this gem. You can find these at https://app.infield.ai/deprecations after signing up.
|
8
8
|
|
9
9
|
Add the gem to your gemfile:
|
10
10
|
|
@@ -15,13 +15,9 @@ Then in `config/application.rb`:
|
|
15
15
|
if ENV['INFIELD_API_KEY']
|
16
16
|
require 'infield'
|
17
17
|
Infield.run(api_key: ENV['INFIELD_API_KEY'],
|
18
|
-
repo_environment_id: ENV['INFIELD_REPO_ENVIRONMENT_ID')
|
18
|
+
repo_environment_id: ENV['INFIELD_REPO_ENVIRONMENT_ID'])
|
19
19
|
end
|
20
20
|
|
21
|
-
And in any environment you want to profile from:
|
22
|
-
|
23
|
-
config.active_support.deprecation = :notify
|
24
|
-
|
25
21
|
## Configuration options
|
26
22
|
|
27
23
|
The infield gem batches requests and sends them asyncronously. You can configure the following options to `Infield.run` (defaults shown here):
|
data/lib/infield/core_ext.rb
CHANGED
@@ -10,5 +10,24 @@ module Infield
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
module InfieldWarningCapture
|
14
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.0")
|
15
|
+
# Ruby 3.0+ supports warn(msg, category: nil, **kwargs)
|
16
|
+
def warn(msg, category: nil, **kwargs)
|
17
|
+
super
|
18
|
+
|
19
|
+
Infield::DeprecationWarning.log(msg, callstack: caller_locations, validated: true) if category == :deprecated
|
20
|
+
end
|
21
|
+
else
|
22
|
+
# Ruby < 3.0 only provides a single argument to warn
|
23
|
+
def warn(msg)
|
24
|
+
super
|
25
|
+
|
26
|
+
Infield::DeprecationWarning.log(msg, callstack: caller_locations, validated: false)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Kernel.extend(Core)
|
32
|
+
Warning.extend(InfieldWarningCapture)
|
14
33
|
end
|
@@ -44,6 +44,23 @@ module Infield
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
def post_deprecation_warnings(tasks)
|
48
|
+
messages = tasks.map { |w| { message: w.message, callstack: w.callstack.map(&:to_s) } }
|
49
|
+
|
50
|
+
uri = infield_api_uri
|
51
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == 'https')) do |http|
|
52
|
+
http.post('/api/raw_deprecation_warnings',
|
53
|
+
{ raw_deprecation_warnings: {
|
54
|
+
repo_environment_id: Infield.repo_environment_id,
|
55
|
+
environment: Infield.environment,
|
56
|
+
messages: messages
|
57
|
+
}
|
58
|
+
}.to_json,
|
59
|
+
{ 'Content-Type' => 'application/json', 'Authorization' => "bearer #{Infield.api_key}" })
|
60
|
+
end
|
61
|
+
rescue *HTTP_ERRORS => e
|
62
|
+
end
|
63
|
+
|
47
64
|
private
|
48
65
|
|
49
66
|
def process_queue
|
@@ -62,17 +79,6 @@ module Infield
|
|
62
79
|
def infield_api_uri
|
63
80
|
URI.parse(Infield.infield_api_url)
|
64
81
|
end
|
65
|
-
|
66
|
-
def post_deprecation_warnings(tasks)
|
67
|
-
messages = tasks.map { |w| { message: w.message } }
|
68
|
-
uri = infield_api_uri
|
69
|
-
Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == 'https')) do |http|
|
70
|
-
http.post('/api/raw_deprecation_warnings',
|
71
|
-
default_api_params.merge(messages: messages).to_json,
|
72
|
-
{ 'Content-Type' => 'application/json', 'Authorization' => "bearer #{Infield.api_key}" })
|
73
|
-
end
|
74
|
-
rescue *HTTP_ERRORS => e
|
75
|
-
end
|
76
82
|
end
|
77
83
|
end
|
78
84
|
|
data/lib/infield/heartbeat.rb
CHANGED
data/lib/infield/rails.rb
CHANGED
@@ -3,8 +3,19 @@
|
|
3
3
|
module Infield
|
4
4
|
class Railtie < Rails::Railtie
|
5
5
|
initializer 'infield.deprecation_warnings', after: 'active_support.deprecation_behavior' do |_app|
|
6
|
-
|
7
|
-
Infield::DeprecationWarning.log(
|
6
|
+
infield_lambda = lambda do |message, callstack, *args|
|
7
|
+
Infield::DeprecationWarning.log(message, callstack: callstack, validated: true)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Rails >= 7.0 makes it so that there are named deprecators that can have their own behavior
|
11
|
+
if Rails.application.respond_to?(:deprecators)
|
12
|
+
Rails.application.deprecators.each do |deprecator|
|
13
|
+
current = Array(deprecator.behavior)
|
14
|
+
deprecator.behavior = [infield_lambda, *current].uniq
|
15
|
+
end
|
16
|
+
else
|
17
|
+
current_behaviors = Array(ActiveSupport::Deprecation.behavior)
|
18
|
+
ActiveSupport::Deprecation.behavior = [infield_lambda, *current_behaviors].uniq
|
8
19
|
end
|
9
20
|
end
|
10
21
|
end
|
data/lib/infield/version.rb
CHANGED
data/lib/infield.rb
CHANGED
@@ -6,7 +6,7 @@ require 'net/http'
|
|
6
6
|
|
7
7
|
require_relative 'infield/version'
|
8
8
|
|
9
|
-
|
9
|
+
require_relative 'infield/core_ext'
|
10
10
|
require_relative 'infield/rails' if defined?(Rails)
|
11
11
|
|
12
12
|
module Infield
|
@@ -25,7 +25,7 @@ module Infield
|
|
25
25
|
raise 'API key is required' unless @api_key
|
26
26
|
raise 'repo_environment_id is required' unless @repo_environment_id
|
27
27
|
|
28
|
-
@environment = environment || defined?(Rails) ? Rails.env : nil
|
28
|
+
@environment = environment || (defined?(Rails) ? Rails.env : nil)
|
29
29
|
|
30
30
|
# Start the deprecation warning processor
|
31
31
|
DeprecationWarning::Runner.run(sleep_interval: sleep_interval, batch_size: batch_size, queue_limit: queue_limit)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infield
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Infield
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: webmock
|