stackify-api-ruby 1.2.10 → 2.0.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: 176a9f9e6549b6c0b3245f2877f07c2ed3f60bce859a0100b0969ba15bc13bed
4
- data.tar.gz: 2a0e49c2d11c76f213601b78ae1c654f350daedc340f1b006bc6574744d881a2
3
+ metadata.gz: f9b32474a263221d764bb23c5d787f80e67072c62e0fcfa9c59eb006cc0900e6
4
+ data.tar.gz: 71bab1fba537e39782c0bdb93a64bbcb66a4385e7bb010b82e50248cfd1e4f25
5
5
  SHA512:
6
- metadata.gz: 93a6a7e73c28b1fa019c3709b48ea4352aaba4d14659a788a60305ea8ea23bc796836c1388d60b2530c4349a40cba9f99aee68ec9b74af593cfa172c4d3500cf
7
- data.tar.gz: e999677aaa16ea4d4b3d3a500869f44b47251f0711573370dae92cc18828fe32cf95cb9781943d2e99e9d35d6a6c12fa1d92fa7d77575ff875a3b58c9d0b0fe9
6
+ metadata.gz: c9953e36b9c753ac698d3d8be088ad22f29d7897357d0ffd25aedeed55c8c6d99969632900c1df40798a5c54356dc2043147b20b4a9f6a691aeb922ed7f050db
7
+ data.tar.gz: 26efa78b3d3a670e93a1bff5fe95fbc69686a230a55ae9863d43bc4cfb8dd2abdee5dfc2470e198114c3de7b130b95807efa2270d95bd7b588ab9239c945b690
data/Gemfile CHANGED
@@ -1,4 +1,11 @@
1
- source 'https://rubygems.org'
1
+ group :test do
2
+ if ENV['STACKIFY_RUBY_TEST']
3
+ gem 'stackify-ruby-apm', '~> 1.16.0', source: ENV['STACKIFY_RUBY_TEST_REPO']
4
+ else
5
+ gem 'stackify-ruby-apm', '~> 1.16.0'
6
+ end
7
+ end
2
8
 
9
+ source 'https://rubygems.org'
3
10
  # Specify your gem's dependencies in stackify.gemspec
4
11
  gemspec
data/Gemfile.lock CHANGED
@@ -1,24 +1,84 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stackify-api-ruby (1.1.0)
4
+ stackify-api-ruby (2.0.0.beta1)
5
5
  faraday (~> 0.8)
6
+ net_http_unix (~> 0.2)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- faraday (0.15.4)
11
+ concurrent-ruby (1.2.2)
12
+ delegate_matcher (0.4.3)
13
+ proc_extensions (~> 0.2)
14
+ diff-lcs (1.4.4)
15
+ et-orbi (1.2.7)
16
+ tzinfo
17
+ faraday (0.17.4)
11
18
  multipart-post (>= 1.2, < 3)
12
- multipart-post (2.0.0)
13
- rake (0.9.6)
19
+ file-tail (1.2.0)
20
+ tins (~> 1.0)
21
+ fugit (1.8.1)
22
+ et-orbi (~> 1, >= 1.2.7)
23
+ raabro (~> 1.4)
24
+ multipart-post (2.1.1)
25
+ net_http_unix (0.2.2)
26
+ proc_extensions (0.2)
27
+ sourcify (~> 0.5)
28
+ raabro (1.4.0)
29
+ rake (10.5.0)
30
+ rspec (3.10.0)
31
+ rspec-core (~> 3.10.0)
32
+ rspec-expectations (~> 3.10.0)
33
+ rspec-mocks (~> 3.10.0)
34
+ rspec-core (3.10.1)
35
+ rspec-support (~> 3.10.0)
36
+ rspec-expectations (3.10.1)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.10.0)
39
+ rspec-mocks (3.10.2)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.10.0)
42
+ rspec-support (3.10.2)
43
+ ruby2ruby (2.5.0)
44
+ ruby_parser (~> 3.1)
45
+ sexp_processor (~> 4.6)
46
+ ruby_parser (3.20.1)
47
+ sexp_processor (~> 4.16)
48
+ rufus-scheduler (3.8.2)
49
+ fugit (~> 1.1, >= 1.1.6)
50
+ sexp_processor (4.17.0)
51
+ sourcify (0.5.0)
52
+ file-tail (>= 1.0.5)
53
+ ruby2ruby (>= 1.2.5)
54
+ ruby_parser (>= 2.0.5)
55
+ sexp_processor (>= 3.0.5)
56
+ stackify-ruby-apm (1.16.0.beta1)
57
+ concurrent-ruby
58
+ delegate_matcher
59
+ faraday
60
+ net_http_unix
61
+ rufus-scheduler
62
+ sync (0.5.0)
63
+ tins (1.32.1)
64
+ sync
65
+ tzinfo (2.0.6)
66
+ concurrent-ruby (~> 1.0)
67
+ tzinfo-data (1.2023.3)
68
+ tzinfo (>= 1.0.0)
14
69
 
15
70
  PLATFORMS
16
71
  ruby
72
+ x64-mingw-ucrt
73
+ x86-mingw32
17
74
 
18
75
  DEPENDENCIES
19
- bundler (~> 1.6)
20
- rake (~> 0)
76
+ bundler (~> 2.0)
77
+ rake (~> 10.0)
78
+ rspec (~> 3.0)
21
79
  stackify-api-ruby!
80
+ stackify-ruby-apm (~> 1.16.0.beta1)
81
+ tzinfo-data
22
82
 
23
83
  BUNDLED WITH
24
- 1.17.3
84
+ 2.4.10
data/README.md CHANGED
@@ -124,6 +124,23 @@ We can configure every metric with settings:
124
124
 
125
125
  Note, "autoreport_last_value_if_nothing_reported" property has influence only on "average" metric.
126
126
 
127
+ ### **Real User Monitoring (RUM)**
128
+
129
+ Real user monitoring injects a script tag containing the [RUM JS](https://stackify.com/retrace-real-user-monitoring/) that is responsible for capturing information about the http requests on the browser. This approach is manual and needs to be configured.
130
+
131
+ #### RUM - Setup
132
+
133
+ ```ruby
134
+ # Configuration - Standard API
135
+ Stackify.setup do |config|
136
+ ...
137
+ config.rum_key = "YourRumKey"
138
+ end
139
+
140
+ # Use this to apply on views
141
+ Stackify.rum.insert_rum_script
142
+ ```
143
+
127
144
  ## Troubleshooting
128
145
 
129
146
  If there are problems, you can enable internal logging of the stackify-api-ruby project. Uncomment out the config.logger and config.logger.level lines in the 'config/initializers/stackify.rb' file:
@@ -24,8 +24,8 @@ module Stackify
24
24
 
25
25
  protected
26
26
 
27
- def method_missing(name, *args, &block)
28
- @logger.send(name, *args, &block)
27
+ def method_missing(name, *args, **kwargs, &block)
28
+ @logger.send(name, *args, **kwargs, &block)
29
29
  end
30
30
 
31
31
  private
@@ -0,0 +1,72 @@
1
+ $apmLoaded = false
2
+
3
+ begin
4
+ require 'stackify-ruby-apm'
5
+ $apmLoaded = true
6
+ rescue LoadError
7
+ end
8
+
9
+ module Stackify
10
+ class Rum
11
+ def initialize(config)
12
+ @config = config
13
+ end
14
+
15
+ def insert_rum_script()
16
+ return StackifyRubyAPM.inject_rum_script if Rum.apm_loaded && defined?(StackifyRubyAPM) && StackifyRubyAPM.respond_to?(:inject_rum_script)
17
+
18
+ return '' unless @config
19
+
20
+ config = @config
21
+
22
+ return '' if config.rum_script_url.to_s.empty? || config.rum_key.to_s.empty?
23
+
24
+ transaction_id = get_transaction_id().to_s
25
+ return '' if transaction_id.empty?
26
+
27
+ reporting_url = get_reporting_url().to_s
28
+ return '' if reporting_url.empty?
29
+
30
+ environment_name = defined?(config.env) ? config.env.to_s : 'Development'
31
+ return '' if environment_name.empty?
32
+
33
+ application_name = defined?(config.app_name) ? config.app_name.to_s : ''
34
+ return '' if application_name.empty?
35
+
36
+ rum_settings = {
37
+ "ID" => transaction_id
38
+ }
39
+
40
+ if !environment_name.empty?
41
+ rum_settings["Env"] = Base64.strict_encode64(environment_name.encode('utf-8'))
42
+ end
43
+
44
+ if !application_name.empty?
45
+ rum_settings["Name"] = Base64.strict_encode64(application_name.strip.encode('utf-8'))
46
+ end
47
+
48
+ if !reporting_url.empty?
49
+ rum_settings["Trans"] = Base64.strict_encode64(reporting_url.encode('utf-8'))
50
+ end
51
+
52
+ rum_content = "<script type=\"text/javascript\">(window.StackifySettings || (window.StackifySettings = #{rum_settings.to_json}))</script><script src=\"#{config.rum_script_url}\" data-key=\"#{config.rum_key}\" async></script>"
53
+ if rum_content.respond_to?(:html_safe)
54
+ rum_content.html_safe
55
+ else
56
+ rum_content
57
+ end
58
+ end
59
+
60
+ def self.apm_loaded
61
+ $apmLoaded
62
+ end
63
+
64
+ def get_reporting_url
65
+ ''
66
+ end
67
+
68
+ def get_transaction_id
69
+ ''
70
+ end
71
+ end
72
+ end
@@ -5,7 +5,8 @@ module Stackify
5
5
  attr_accessor :api_key, :app_name, :app_location, :env, :log_level, :logger,
6
6
  :proxy, :mode, :base_api_url, :api_enabled, :transport, :errors, :http_endpoint, :stdout_output, :buffered_logger
7
7
 
8
- attr_reader :send_interval, :flood_limit, :queue_max_size, :agent_log_url, :unix_socket_path, :http_endpoint
8
+ attr_reader :send_interval, :flood_limit, :queue_max_size, :agent_log_url, :unix_socket_path, :http_endpoint,
9
+ :rum_key, :rum_script_url
9
10
 
10
11
  def initialize
11
12
  @base_api_url = 'https://api.stackify.com'
@@ -27,6 +28,11 @@ module Stackify
27
28
  @http_endpoint = get_env 'STACKIFY_TRANSPORT_HTTP_ENDPOINT', 'https://localhost:10601'
28
29
  @stdout_output = false
29
30
  @buffered_logger = false
31
+ @default_rum_script_url = 'https://stckjs.stackify.com/stckjs.js'
32
+ @default_rum_key = ''
33
+
34
+ self.rum_key = get_env 'RETRACE_RUM_KEY', @default_rum_key
35
+ self.rum_script_url = get_env 'RETRACE_RUM_SCRIPT_URL', @default_rum_script_url
30
36
  end
31
37
 
32
38
  def get_env env_key, default
@@ -52,6 +58,28 @@ module Stackify
52
58
  @errors << 'Transport should be one of these values: [agent_socket, agent_http, default]. Should be a String.'
53
59
  end
54
60
 
61
+ def rum_script_url=(rum_script_url)
62
+ if rum_script_url.empty?
63
+ @rum_script_url = @default_rum_script_url
64
+ return
65
+ end
66
+
67
+ if validate_rum_script_url(rum_script_url)
68
+ @rum_script_url = rum_script_url
69
+ end
70
+ end
71
+
72
+ def rum_key=(rum_key)
73
+ if rum_key.empty?
74
+ @rum_key = @default_rum_key
75
+ return
76
+ end
77
+
78
+ if validate_rum_key(rum_key)
79
+ @rum_key = rum_key
80
+ end
81
+ end
82
+
55
83
  private
56
84
 
57
85
  def validate_config_types
@@ -110,5 +138,27 @@ module Stackify
110
138
  return true if MODES.has_value? @mode
111
139
  @errors << 'Mode should be one of these values: [:both, :logging, :metrics]'
112
140
  end
141
+
142
+ def validate_rum_script_url(rum_script_url)
143
+ result = false
144
+ if rum_script_url.is_a?(String) && !rum_script_url.empty?
145
+ result = rum_script_url =~ /^((((https?|ftps?|gopher|telnet|nntp):\/\/)|(mailto:|news:))(%[0-9A-Fa-f]{2}|[\-\(\)_\.!~*';\/?:@&=+$,A-Za-z0-9])+)([\)\.!';\/?:,][\[:blank:|:blank:\]])?$/
146
+ end
147
+ if !result
148
+ @errors << 'RUM Script URL is in invalid format.'
149
+ end
150
+ result
151
+ end
152
+
153
+ def validate_rum_key(rum_key)
154
+ result = false
155
+ if rum_key.is_a?(String) && !rum_key.empty?
156
+ result = rum_key =~ %r{^[A-Za-z0-9_-]+$}
157
+ end
158
+ if !result
159
+ @errors << 'RUM Key is in invalid format.'
160
+ end
161
+ result
162
+ end
113
163
  end
114
164
  end
@@ -1,3 +1,3 @@
1
1
  module Stackify
2
- VERSION = '1.2.10'
2
+ VERSION = '2.0.0'
3
3
  end
@@ -37,6 +37,7 @@ module Stackify
37
37
  autoload :StringException, 'stackify/error'
38
38
  autoload :ErrorsGovernor, 'stackify/errors_governor'
39
39
  autoload :Metrics, 'stackify/metrics/metrics'
40
+ autoload :Rum, 'stackify/rum'
40
41
 
41
42
  include Authorizable
42
43
 
@@ -48,6 +49,10 @@ module Stackify
48
49
  @config ||= Stackify::Configuration.new
49
50
  end
50
51
 
52
+ def rum
53
+ @rum ||= Stackify::Rum.new(configuration)
54
+ end
55
+
51
56
  def setup
52
57
  @workers = []
53
58
  yield(configuration) if block_given?
data/spec/rum_spec.rb ADDED
@@ -0,0 +1,291 @@
1
+ require 'spec_helper'
2
+ require 'stackify-api-ruby'
3
+
4
+ module Stackify
5
+ RSpec.describe 'Rum - APM not loaded - Normal' do
6
+ it 'returns rum script with complete information from ENV' do
7
+ ENV['RETRACE_RUM_KEY'] = 'test-key'
8
+ ENV['RETRACE_RUM_SCRIPT_URL'] = 'https://test.com/test.js'
9
+
10
+ config = Stackify::Configuration.new
11
+ config.app_name = 'test'
12
+ config.env = 'test-env'
13
+
14
+ rum = Stackify::Rum.new(config)
15
+ reporting_url = "test reporting url"
16
+ transaction_id = "123-id"
17
+ rum_script_url = 'https://test.com/test.js'
18
+
19
+ rum_settings = {
20
+ "ID" => '123-id',
21
+ "Env" => Base64.strict_encode64('test-env'.encode('utf-8')),
22
+ "Name" => Base64.strict_encode64('test'.strip.encode('utf-8')), # TODO: Add helper function
23
+ "Trans" => Base64.strict_encode64('test reporting url'.encode('utf-8'))
24
+ }
25
+
26
+ expected_rum_script = "<script type=\"text/javascript\">(window.StackifySettings || (window.StackifySettings = #{rum_settings.to_json()}))<\/script><script src=\"#{rum_script_url}\" data-key=\"#{config.rum_key}\" async></script>"
27
+
28
+ allow(rum).to receive(:get_reporting_url).and_return(reporting_url)
29
+ allow(rum).to receive(:get_transaction_id).and_return(transaction_id)
30
+ allow(Rum).to receive(:apm_loaded).and_return(false)
31
+
32
+ rum_script = rum.insert_rum_script
33
+
34
+ expect(rum.get_reporting_url).to eq reporting_url
35
+ expect(rum.get_transaction_id).to eq transaction_id
36
+ expect(rum_script.to_s).not_to be_empty
37
+ expect(rum_script).to eq expected_rum_script
38
+
39
+ ENV.delete('RETRACE_RUM_KEY')
40
+ ENV.delete('RETRACE_RUM_SCRIPT_URL')
41
+ end
42
+
43
+ it 'returns rum script with complete information from Config' do
44
+ config = Stackify::Configuration.new
45
+ config.app_name = 'test'
46
+ config.env = 'test-env'
47
+ config.rum_script_url = 'https://test.com/test.js'
48
+ config.rum_key = 'asd'
49
+
50
+ rum = Stackify::Rum.new(config)
51
+ reporting_url = "test reporting url"
52
+ transaction_id = "123-id"
53
+ rum_script_url = 'https://test.com/test.js'
54
+ rum_key = 'asd'
55
+
56
+ rum_settings = {
57
+ "ID" => '123-id',
58
+ "Env" => Base64.strict_encode64('test-env'.encode('utf-8')),
59
+ "Name" => Base64.strict_encode64('test'.strip.encode('utf-8')), # TODO: Add helper function
60
+ "Trans" => Base64.strict_encode64('test reporting url'.encode('utf-8'))
61
+ }
62
+
63
+ expected_rum_script = "<script type=\"text/javascript\">(window.StackifySettings || (window.StackifySettings = #{rum_settings.to_json()}))<\/script><script src=\"#{rum_script_url}\" data-key=\"#{rum_key}\" async></script>"
64
+
65
+ allow(rum).to receive(:get_reporting_url).and_return(reporting_url)
66
+ allow(rum).to receive(:get_transaction_id).and_return(transaction_id)
67
+ allow(Rum).to receive(:apm_loaded).and_return(false)
68
+
69
+ rum_script = rum.insert_rum_script
70
+
71
+ expect(rum.get_reporting_url).to eq reporting_url
72
+ expect(rum.get_transaction_id).to eq transaction_id
73
+ expect(rum_script.to_s).not_to be_empty
74
+ expect(rum_script).to eq expected_rum_script
75
+ end
76
+ end
77
+
78
+ RSpec.describe 'Rum - APM not loaded - Invalid' do
79
+ it 'returns rum script with invalid rum script url from Config' do
80
+ config = Stackify::Configuration.new
81
+ config.app_name = 'test'
82
+ config.env = 'test-env'
83
+ config.rum_script_url = 'test.js'
84
+ config.rum_key = 'asd'
85
+
86
+ rum = Stackify::Rum.new(config)
87
+ reporting_url = "test reporting url"
88
+ transaction_id = "123-id"
89
+ rum_script_url = 'https://stckjs.stackify.com/stckjs.js'
90
+ rum_key = 'asd'
91
+
92
+ rum_settings = {
93
+ "ID" => '123-id',
94
+ "Env" => Base64.strict_encode64('test-env'.encode('utf-8')),
95
+ "Name" => Base64.strict_encode64('test'.strip.encode('utf-8')), # TODO: Add helper function
96
+ "Trans" => Base64.strict_encode64('test reporting url'.encode('utf-8'))
97
+ }
98
+
99
+ expected_rum_script = "<script type=\"text/javascript\">(window.StackifySettings || (window.StackifySettings = #{rum_settings.to_json()}))<\/script><script src=\"#{rum_script_url}\" data-key=\"#{rum_key}\" async></script>"
100
+
101
+ allow(rum).to receive(:get_reporting_url).and_return(reporting_url)
102
+ allow(rum).to receive(:get_transaction_id).and_return(transaction_id)
103
+ allow(Rum).to receive(:apm_loaded).and_return(false)
104
+
105
+ rum_script = rum.insert_rum_script
106
+
107
+ expect(rum.get_reporting_url).to eq reporting_url
108
+ expect(rum.get_transaction_id).to eq transaction_id
109
+ expect(rum_script.to_s).not_to be_empty
110
+ expect(rum_script).to eq expected_rum_script
111
+ end
112
+
113
+ it 'returns rum script with invalid rum key from Config' do
114
+ config = Stackify::Configuration.new
115
+ config.app_name = 'test'
116
+ config.env = 'test-env'
117
+ config.rum_script_url = 'test.js'
118
+ config.rum_key = '`asd'
119
+
120
+ rum = Stackify::Rum.new(config)
121
+ reporting_url = "test reporting url"
122
+ transaction_id = "123-id"
123
+ rum_script_url = 'https://stckjs.stackify.com/stckjs.js'
124
+ rum_key = 'asd'
125
+
126
+ rum_settings = {
127
+ "ID" => '123-id',
128
+ "Env" => Base64.strict_encode64('test-env'.encode('utf-8')),
129
+ "Name" => Base64.strict_encode64('test'.strip.encode('utf-8')), # TODO: Add helper function
130
+ "Trans" => Base64.strict_encode64('test reporting url'.encode('utf-8'))
131
+ }
132
+
133
+ expected_rum_script = "<script type=\"text/javascript\">(window.StackifySettings || (window.StackifySettings = #{rum_settings.to_json()}))<\/script><script src=\"#{rum_script_url}\" data-key=\"#{rum_key}\" async></script>"
134
+
135
+ allow(rum).to receive(:get_reporting_url).and_return(reporting_url)
136
+ allow(rum).to receive(:get_transaction_id).and_return(transaction_id)
137
+ allow(Rum).to receive(:apm_loaded).and_return(false)
138
+
139
+ rum_script = rum.insert_rum_script
140
+
141
+ expect(rum.get_reporting_url).to eq reporting_url
142
+ expect(rum.get_transaction_id).to eq transaction_id
143
+ expect(rum_script.to_s).to be_empty
144
+ expect(rum_script).not_to eq expected_rum_script
145
+ expect(config.rum_key).to be_empty
146
+ end
147
+
148
+ it 'returns rum script with no app name' do
149
+ config = Stackify::Configuration.new
150
+ config.app_name = ''
151
+ config.env = 'test-env'
152
+ config.rum_script_url = 'test.js'
153
+ config.rum_key = '`asd'
154
+
155
+ rum = Stackify::Rum.new(config)
156
+
157
+ reporting_url = "test reporting url"
158
+ transaction_id = "123-id"
159
+
160
+ allow(rum).to receive(:get_reporting_url).and_return(reporting_url)
161
+ allow(rum).to receive(:get_transaction_id).and_return(transaction_id)
162
+ allow(Rum).to receive(:apm_loaded).and_return(false)
163
+
164
+ rum_script = rum.insert_rum_script
165
+
166
+ expect(rum.get_reporting_url).to eq reporting_url
167
+ expect(rum.get_transaction_id).to eq transaction_id
168
+ expect(rum_script.to_s).to be_empty
169
+ expect(config.rum_key).to be_empty
170
+ expect(config.app_name).to be_empty
171
+ end
172
+
173
+ it 'returns rum script with no env' do
174
+ config = Stackify::Configuration.new
175
+ config.app_name = 'test'
176
+ config.rum_script_url = 'test.js'
177
+ config.rum_key = 'asd'
178
+
179
+ rum = Stackify::Rum.new(config)
180
+ reporting_url = "test reporting url"
181
+ transaction_id = "123-id"
182
+ rum_script_url = 'https://stckjs.stackify.com/stckjs.js'
183
+ rum_key = 'asd'
184
+
185
+ rum_settings = {
186
+ "ID" => '123-id',
187
+ "Env" => Base64.strict_encode64('production'.encode('utf-8')),
188
+ "Name" => Base64.strict_encode64('test'.strip.encode('utf-8')), # TODO: Add helper function
189
+ "Trans" => Base64.strict_encode64('test reporting url'.encode('utf-8'))
190
+ }
191
+
192
+ expected_rum_script = "<script type=\"text/javascript\">(window.StackifySettings || (window.StackifySettings = #{rum_settings.to_json()}))<\/script><script src=\"#{rum_script_url}\" data-key=\"#{rum_key}\" async></script>"
193
+
194
+ allow(rum).to receive(:get_reporting_url).and_return(reporting_url)
195
+ allow(rum).to receive(:get_transaction_id).and_return(transaction_id)
196
+ allow(Rum).to receive(:apm_loaded).and_return(false)
197
+
198
+ rum_script = rum.insert_rum_script
199
+
200
+ expect(rum.get_reporting_url).to eq reporting_url
201
+ expect(rum.get_transaction_id).to eq transaction_id
202
+ expect(rum_script.to_s).not_to be_empty
203
+ expect(rum_script).to eq expected_rum_script
204
+ expect(config.env).to eq :production
205
+ end
206
+
207
+ it 'returns rum script with no transaction id' do
208
+ config = Stackify::Configuration.new
209
+ config.app_name = 'test'
210
+ config.env = 'test-env'
211
+ config.rum_script_url = 'test.js'
212
+ config.rum_key = 'asd'
213
+
214
+ rum = Stackify::Rum.new(config)
215
+
216
+ reporting_url = "test reporting url"
217
+ transaction_id = ""
218
+
219
+ allow(rum).to receive(:get_reporting_url).and_return(reporting_url)
220
+ allow(rum).to receive(:get_transaction_id).and_return(transaction_id)
221
+ allow(Rum).to receive(:apm_loaded).and_return(false)
222
+
223
+ rum_script = rum.insert_rum_script
224
+
225
+ expect(rum.get_reporting_url).to eq reporting_url
226
+ expect(rum.get_transaction_id).to eq ""
227
+ expect(rum_script.to_s).to be_empty
228
+ end
229
+
230
+ it 'returns rum script with no reporting url' do
231
+ config = Stackify::Configuration.new
232
+ config.app_name = 'test'
233
+ config.env = 'test-env'
234
+ config.rum_script_url = 'test.js'
235
+ config.rum_key = 'asd'
236
+
237
+ rum = Stackify::Rum.new(config)
238
+
239
+ reporting_url = ""
240
+ transaction_id = "test-123"
241
+
242
+ allow(rum).to receive(:get_reporting_url).and_return(reporting_url)
243
+ allow(rum).to receive(:get_transaction_id).and_return(transaction_id)
244
+ allow(Rum).to receive(:apm_loaded).and_return(false)
245
+
246
+ rum_script = rum.insert_rum_script
247
+
248
+ expect(rum.get_reporting_url).to eq ""
249
+ expect(rum.get_transaction_id).to eq transaction_id
250
+ expect(rum_script.to_s).to be_empty
251
+ end
252
+ end
253
+
254
+ RSpec.describe 'Rum - APM loaded - Normal' do
255
+ it 'returns rum script with complete information from ENV' do
256
+ ENV['RETRACE_RUM_KEY'] = 'test-key'
257
+ ENV['RETRACE_RUM_SCRIPT_URL'] = 'https://test.com/test.js'
258
+ ENV['TZ'] = 'Europe/Paris' # For error
259
+
260
+ config = Stackify::Configuration.new
261
+ rum = Stackify::Rum.new(config)
262
+ reporting_url = "test reporting url"
263
+ transaction_id = "123-id"
264
+ rum_script_url = 'https://test.com/test.js'
265
+ rum_script = ""
266
+
267
+ StackifyRubyAPM.start
268
+ transaction = StackifyRubyAPM.transaction 'RUM Script Injection test' do
269
+ rum_script = rum.insert_rum_script
270
+ end.submit 200
271
+ StackifyRubyAPM.stop
272
+
273
+ rum_settings = {
274
+ "ID" => transaction.id(),
275
+ "Env" => Base64.strict_encode64('test'.encode('utf-8')),
276
+ "Name" => Base64.strict_encode64('Ruby Application'.strip.encode('utf-8')), # TODO: Add helper function
277
+ "Trans" => Base64.strict_encode64('RUM Script Injection test'.encode('utf-8'))
278
+ }
279
+
280
+ expected_rum_script = "<script type=\"text/javascript\">(window.StackifySettings || (window.StackifySettings = #{rum_settings.to_json()}))<\/script><script src=\"#{rum_script_url}\" data-key=\"#{config.rum_key}\" async></script>"
281
+
282
+ ENV.delete('TZ')
283
+ ENV.delete('RETRACE_RUM_KEY')
284
+ ENV.delete('RETRACE_RUM_SCRIPT_URL')
285
+
286
+ expect(rum_script.to_s).not_to be_empty
287
+ expect(rum_script).to eq expected_rum_script
288
+ end
289
+ end
290
+ end
291
+
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,12 @@
1
+ ENV['RAILS_ENV'] = ENV['RACK_ENV'] = 'test'
2
+ require 'bundler/setup'
3
+
4
+ # auto-require default gems + gems under test
5
+ Bundler.require :default, 'test'
6
+
7
+ require 'logger'
8
+ require 'stackify_ruby_apm'
9
+
1
10
  RSpec.configure do |config|
2
11
 
3
12
  config.filter_run :focus
@@ -12,15 +12,21 @@ Gem::Specification.new do |spec|
12
12
  spec.description = 'Stackify Logs and Metrics API for Ruby'
13
13
  spec.homepage = 'http://www.stackify.com/'
14
14
  spec.license = 'Apache-2.0'
15
- spec.required_ruby_version = '>= 1.9'
15
+ spec.required_ruby_version = '>= 3.0'
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0")
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_development_dependency 'bundler', '~> 1.6'
23
- spec.add_development_dependency 'rake', '~> 0'
22
+ spec.add_development_dependency 'bundler', '~> 2.0'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+
26
+ if RUBY_PLATFORM =~ /mingw32|win32|x64/
27
+ spec.add_development_dependency 'tzinfo-data'
28
+ end
29
+
24
30
  spec.add_runtime_dependency 'faraday', '~> 0.8'
25
31
  spec.add_runtime_dependency 'net_http_unix', '~> 0.2'
26
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackify-api-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.10
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stackify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-01 00:00:00.000000000 Z
11
+ date: 2023-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: faraday
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +122,7 @@ files:
108
122
  - lib/stackify/metrics/monitor.rb
109
123
  - lib/stackify/msgs_queue.rb
110
124
  - lib/stackify/rack/errors_catcher.rb
125
+ - lib/stackify/rum.rb
111
126
  - lib/stackify/schedule_delay.rb
112
127
  - lib/stackify/schedule_task.rb
113
128
  - lib/stackify/scheduler.rb
@@ -124,6 +139,7 @@ files:
124
139
  - lib/stackify/workers/logs_sender_worker.rb
125
140
  - lib/stackify/workers/msgs_queue_worker.rb
126
141
  - lib/stackify/workers/worker.rb
142
+ - spec/rum_spec.rb
127
143
  - spec/spec_helper.rb
128
144
  - stackify-api-ruby.gemspec
129
145
  homepage: http://www.stackify.com/
@@ -138,16 +154,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
154
  requirements:
139
155
  - - ">="
140
156
  - !ruby/object:Gem::Version
141
- version: '1.9'
157
+ version: '3.0'
142
158
  required_rubygems_version: !ruby/object:Gem::Requirement
143
159
  requirements:
144
160
  - - ">="
145
161
  - !ruby/object:Gem::Version
146
162
  version: '0'
147
163
  requirements: []
148
- rubygems_version: 3.0.1
164
+ rubygems_version: 3.4.10
149
165
  signing_key:
150
166
  specification_version: 4
151
167
  summary: Stackify API for Ruby
152
168
  test_files:
169
+ - spec/rum_spec.rb
153
170
  - spec/spec_helper.rb