stackify-api-ruby 1.2.10 → 1.3.0.beta1

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: ae96dffa800668cd0f8ab55fc62232c43951fbe5bf9700992698ece32bbbf006
4
+ data.tar.gz: 7e44e75717ecb342cdb632766708bb765793df1a92b534e689d59079c43d2bbd
5
5
  SHA512:
6
- metadata.gz: 93a6a7e73c28b1fa019c3709b48ea4352aaba4d14659a788a60305ea8ea23bc796836c1388d60b2530c4349a40cba9f99aee68ec9b74af593cfa172c4d3500cf
7
- data.tar.gz: e999677aaa16ea4d4b3d3a500869f44b47251f0711573370dae92cc18828fe32cf95cb9781943d2e99e9d35d6a6c12fa1d92fa7d77575ff875a3b58c9d0b0fe9
6
+ metadata.gz: 032502e0aff449fa9ad239f282751ee0699cffcca713f14dff414eaac255cbabba348bcbabc5f5800be8aadecd787c1a7ba9d92620a86cb41ee7f579a1f6d56b
7
+ data.tar.gz: 8e93149a91583a7f9accc6d6ba1e87767ea8daa96049fc25941b89b27f4a1c459e4d6cce050126306b8097d979b993b5ddfe0c984191b7f503a6bc3af50948a3
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.15', source: ENV['STACKIFY_RUBY_TEST_REPO']
4
+ else
5
+ gem 'stackify-ruby-apm', '~> 1.15'
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,62 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stackify-api-ruby (1.1.0)
4
+ stackify-api-ruby (1.3.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.1.9)
12
+ diff-lcs (1.4.4)
13
+ et-orbi (1.2.4)
14
+ tzinfo
15
+ faraday (0.17.4)
11
16
  multipart-post (>= 1.2, < 3)
12
- multipart-post (2.0.0)
17
+ fugit (1.5.0)
18
+ et-orbi (~> 1.1, >= 1.1.8)
19
+ raabro (~> 1.4)
20
+ multipart-post (2.1.1)
21
+ net_http_unix (0.2.2)
22
+ raabro (1.4.0)
13
23
  rake (0.9.6)
24
+ rspec (3.10.0)
25
+ rspec-core (~> 3.10.0)
26
+ rspec-expectations (~> 3.10.0)
27
+ rspec-mocks (~> 3.10.0)
28
+ rspec-core (3.10.1)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-expectations (3.10.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.10.0)
33
+ rspec-mocks (3.10.2)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.10.0)
36
+ rspec-support (3.10.2)
37
+ rufus-scheduler (3.8.0)
38
+ fugit (~> 1.1, >= 1.1.6)
39
+ stackify-ruby-apm (1.15.1)
40
+ concurrent-ruby (~> 1.0)
41
+ faraday (~> 0.8)
42
+ net_http_unix (~> 0.2)
43
+ rufus-scheduler (~> 3.0)
44
+ tzinfo (2.0.4)
45
+ concurrent-ruby (~> 1.0)
46
+ tzinfo-data (1.2021.1)
47
+ tzinfo (>= 1.0.0)
14
48
 
15
49
  PLATFORMS
16
50
  ruby
51
+ x86-mingw32
17
52
 
18
53
  DEPENDENCIES
19
54
  bundler (~> 1.6)
20
55
  rake (~> 0)
56
+ rspec (~> 3.0)
21
57
  stackify-api-ruby!
58
+ stackify-ruby-apm (~> 1.15)
59
+ tzinfo-data
22
60
 
23
61
  BUNDLED WITH
24
- 1.17.3
62
+ 1.17.13
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:
@@ -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?
@@ -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 = '1.3.0.beta1'
3
3
  end
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
@@ -21,6 +21,12 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_development_dependency 'bundler', '~> 1.6'
23
23
  spec.add_development_dependency 'rake', '~> 0'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+
26
+ if RUBY_PLATFORM == 'i386-mingw32'
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: 1.3.0.beta1
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: 2021-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '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/
@@ -141,13 +157,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
157
  version: '1.9'
142
158
  required_rubygems_version: !ruby/object:Gem::Requirement
143
159
  requirements:
144
- - - ">="
160
+ - - ">"
145
161
  - !ruby/object:Gem::Version
146
- version: '0'
162
+ version: 1.3.1
147
163
  requirements: []
148
164
  rubygems_version: 3.0.1
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