rorvswild 1.6.5 → 1.7.0

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: 43d62b43885f0c12279773dc060954a30cfa80d0f19ca838398ba77c6b5b459b
4
- data.tar.gz: fd61331e3b88e2b1b682b0ff227349a99a806eaacbc4b64ec7ea0e22b509ae65
3
+ metadata.gz: e0dc87868138ecb496f99d1d4adc670f0776b3fe4fa8312ec8c9126e33800c62
4
+ data.tar.gz: 05334e640532cefa98e18c895d2c599d45714812ed948dd5150748df0d139722
5
5
  SHA512:
6
- metadata.gz: 8022d6596eab0d903c5f59b6632e2b15b3c4ad7720af47f0f490ba6bb1d70867f3bd1c9e6d022bce9472002482338c0432b8f85f248bba0a8d7168f3f385d30a
7
- data.tar.gz: db65a5140351071e2ef1b668374372181d518848411fc379e46e4b1eb86ef01286dc643053728a317b3c6261e9ff07e8e5031f32f4a88d8077f62519febef46f
6
+ metadata.gz: e1476eb8421864a1cdfc904988204b5da750249d1054d72ee0a1d2ab1a07a1aba14fe9851ee54a66f9f7cae442f9e025b216f5b1d99fc73f26474f2c3e8a0347
7
+ data.tar.gz: 66e61e2d41d97d42a80e8f6854badd6cd1247449a8a1e3192415885864bdca62339aff4b23640edd067f8931f4e9c1f81bbda84ec4df975e61be3e34df1556ed
@@ -133,6 +133,10 @@ module RorVsWild
133
133
  current_data[:error_context] = hash if current_data
134
134
  end
135
135
 
136
+ def send_server_timing=(boolean)
137
+ current_data[:send_server_timing] = boolean if current_data
138
+ end
139
+
136
140
  def current_data
137
141
  Thread.current[:rorvswild_data]
138
142
  end
@@ -182,6 +186,7 @@ module RorVsWild
182
186
 
183
187
  def queue_request
184
188
  (data = cleanup_data) && data[:name] && queue.push_request(data)
189
+ data
185
190
  end
186
191
 
187
192
  def queue_job
@@ -11,7 +11,7 @@ module RorVsWild
11
11
  CERTIFICATE_AUTHORITIES_PATH = File.expand_path("../../../cacert.pem", __FILE__)
12
12
  DEFAULT_TIMEOUT = 10
13
13
 
14
- attr_reader :api_url, :api_key, :timeout, :threads
14
+ attr_reader :api_url, :api_key, :timeout, :threads, :config
15
15
 
16
16
  def initialize(config)
17
17
  Kernel.at_exit(&method(:at_exit))
@@ -59,7 +59,7 @@ module RorVsWild
59
59
  end
60
60
 
61
61
  def self.read_from_scalingo
62
- @revision = ENV["SOURCE_VERSION"]
62
+ @revision = ENV["CONTAINER_VERSION"] || ENV["SOURCE_VERSION"]
63
63
  end
64
64
 
65
65
  def self.read_from_git
@@ -48,7 +48,9 @@ production:
48
48
  # - Redis
49
49
  # - Resque
50
50
  # - Sidekiq
51
+ #
51
52
  # logger: log/rorvswild.log # By default it uses Rails.logger or Logger.new(STDOUT)
53
+ #
52
54
  # # Deployment tracking is working without any actions from your part if the Rails app
53
55
  # # is inside a Git repositoriy, is deployed via Capistrano.
54
56
  # # In the other cases, you can provide the following details.
@@ -57,6 +59,16 @@ production:
57
59
  # description: <%= "Eventually if you have a description such as a Git message" %>
58
60
  # author: <%= "Author's name of the deployment" %>
59
61
  # email: <%= "emailOf@theAuthor.example" %>
62
+ #
63
+ # Sampling allows to send a fraction of jobs and requests.
64
+ # If your app is sending hundred of millions of requests per month,
65
+ # you will probably get the same precision if you send only a fraction of it.
66
+ # Thus, it decreases the bill at the end of the month. It's also a mitigation if
67
+ # your app is a target of a DoS. There are 2 parameters to dissociate requests and jobs.
68
+ # Indeed, for an app handling a lot of request but very few jobs, it makes sens to sample
69
+ # the former but not the latter.
70
+ # request_sampling_rate: 0.25 # 25% of requests are sent
71
+ # job_sampling_rate: 0.5 # 50% of jobs are sent
60
72
  YAML
61
73
  end
62
74
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RorVsWild
2
4
  module Local
3
5
  class Middleware
@@ -99,7 +101,7 @@ module RorVsWild
99
101
  end
100
102
 
101
103
  def empty_html_page
102
- "<!DOCTYPE html>\n<html><head></head><body></body></html>"
104
+ "<!DOCTYPE html>\n<html><head></head><body></body></html>".dup
103
105
  end
104
106
 
105
107
  def log_incompatible_middleware_warning
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RorVsWild
2
4
  module Plugin
3
5
  class Middleware
@@ -13,19 +15,35 @@ module RorVsWild
13
15
 
14
16
  def call(env)
15
17
  RorVsWild.agent.start_request
16
- RorVsWild.agent.current_data[:path] = env["ORIGINAL_FULLPATH".freeze]
18
+ RorVsWild.agent.current_data[:path] = env["ORIGINAL_FULLPATH"]
17
19
  section = RorVsWild::Section.start
18
20
  section.file, section.line = rails_engine_location
19
- section.command = "Rails::Engine#call".freeze
20
- @app.call(env)
21
+ section.command = "Rails::Engine#call"
22
+ code, headers, body = @app.call(env)
23
+ [code, headers, body]
21
24
  ensure
22
25
  RorVsWild::Section.stop
23
- RorVsWild.agent.stop_request
26
+ inject_server_timing(RorVsWild.agent.stop_request, headers)
24
27
  end
25
28
 
26
29
  def rails_engine_location
27
30
  @rails_engine_location = ::Rails::Engine.instance_method(:call).source_location
28
31
  end
32
+
33
+ def format_server_timing(sections)
34
+ sections.sort_by(&:self_runtime).reverse.map do |section|
35
+ if section.kind == "view"
36
+ "#{section.kind};dur=#{section.self_runtime};desc=\"#{section.file}\""
37
+ else
38
+ "#{section.kind};dur=#{section.self_runtime};desc=\"#{section.file}:#{section.line}\""
39
+ end
40
+ end.join(", ")
41
+ end
42
+
43
+ def inject_server_timing(data, headers)
44
+ return if !data || !data[:send_server_timing] || !(sections = data[:sections])
45
+ headers["Server-Timing"] = format_server_timing(sections)
46
+ end
29
47
  end
30
48
  end
31
49
  end
@@ -14,15 +14,17 @@ module RorVsWild
14
14
  @client = client
15
15
  @mutex = Mutex.new
16
16
  @metrics = RorVsWild::Metrics.new if defined?(Metrics)
17
+ @request_sampling_rate = client.config[:request_sampling_rate]
18
+ @job_sampling_rate = client.config[:job_sampling_rate]
17
19
  Kernel.at_exit { flush }
18
20
  end
19
21
 
20
22
  def push_job(data)
21
- push_to(jobs, data)
23
+ push_to(jobs, data) if !@job_sampling_rate || rand <= @job_sampling_rate
22
24
  end
23
25
 
24
26
  def push_request(data)
25
- push_to(requests, data)
27
+ push_to(requests, data) if !@request_sampling_rate || rand <= @request_sampling_rate
26
28
  end
27
29
 
28
30
  def push_to(array, data)
@@ -1,3 +1,3 @@
1
1
  module RorVsWild
2
- VERSION = "1.6.5".freeze
2
+ VERSION = "1.7.0".freeze
3
3
  end
data/lib/rorvswild.rb CHANGED
@@ -50,6 +50,10 @@ module RorVsWild
50
50
  agent.merge_error_context(hash) if agent
51
51
  end
52
52
 
53
+ def self.send_server_timing=(boolean)
54
+ agent.send_server_timing = boolean if agent
55
+ end
56
+
53
57
  def self.initialize_logger(destination = nil)
54
58
  if destination.respond_to?(:info) && destination.respond_to?(:warn) && destination.respond_to?(:error)
55
59
  destination
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rorvswild
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.5
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Bernard
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-04-18 00:00:00.000000000 Z
12
+ date: 2024-04-22 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Performances and errors insights for rails developers.
15
15
  email: