newrelic_rpm 3.4.1 → 3.4.2.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of newrelic_rpm might be problematic. Click here for more details.

Files changed (81) hide show
  1. data/CHANGELOG +7 -0
  2. data/ReleaseNotes.md +638 -0
  3. data/lib/new_relic/agent/agent.rb +44 -56
  4. data/lib/new_relic/agent/beacon_configuration.rb +1 -1
  5. data/lib/new_relic/agent/browser_monitoring.rb +80 -42
  6. data/lib/new_relic/agent/configuration/defaults.rb +75 -0
  7. data/lib/new_relic/agent/configuration/environment_source.rb +42 -0
  8. data/lib/new_relic/agent/configuration/manager.rb +100 -0
  9. data/lib/new_relic/agent/configuration/server_source.rb +24 -0
  10. data/lib/new_relic/agent/configuration/yaml_source.rb +61 -0
  11. data/lib/new_relic/agent/configuration.rb +48 -0
  12. data/lib/new_relic/agent/error_collector.rb +10 -14
  13. data/lib/new_relic/agent/instrumentation/active_record.rb +1 -5
  14. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +20 -4
  15. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -1
  16. data/lib/new_relic/agent/instrumentation/memcache.rb +2 -2
  17. data/lib/new_relic/agent/instrumentation/metric_frame.rb +1 -1
  18. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +3 -3
  19. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +2 -2
  20. data/lib/new_relic/agent/instrumentation/resque.rb +1 -1
  21. data/lib/new_relic/agent/method_tracer.rb +1 -1
  22. data/lib/new_relic/agent/new_relic_service.rb +18 -9
  23. data/lib/new_relic/agent/pipe_channel_manager.rb +5 -6
  24. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +2 -5
  25. data/lib/new_relic/agent/sql_sampler.rb +11 -35
  26. data/lib/new_relic/agent/stats_engine/transactions.rb +2 -2
  27. data/lib/new_relic/agent/transaction_info.rb +24 -4
  28. data/lib/new_relic/agent/transaction_sample_builder.rb +2 -3
  29. data/lib/new_relic/agent/transaction_sampler.rb +9 -16
  30. data/lib/new_relic/agent.rb +4 -1
  31. data/lib/new_relic/collection_helper.rb +1 -1
  32. data/lib/new_relic/commands/deployments.rb +5 -3
  33. data/lib/new_relic/control/class_methods.rb +2 -3
  34. data/lib/new_relic/control/frameworks/rails.rb +8 -8
  35. data/lib/new_relic/control/frameworks/ruby.rb +2 -2
  36. data/lib/new_relic/control/instance_methods.rb +26 -32
  37. data/lib/new_relic/control/logging_methods.rb +5 -23
  38. data/lib/new_relic/control/server_methods.rb +11 -18
  39. data/lib/new_relic/control.rb +0 -1
  40. data/lib/new_relic/delayed_job_injection.rb +1 -1
  41. data/lib/new_relic/language_support.rb +8 -0
  42. data/lib/new_relic/noticed_error.rb +1 -1
  43. data/lib/new_relic/rack/browser_monitoring.rb +18 -6
  44. data/lib/new_relic/version.rb +2 -2
  45. data/newrelic.yml +0 -4
  46. data/newrelic_rpm.gemspec +16 -6
  47. data/test/config/newrelic.yml +3 -2
  48. data/test/new_relic/agent/agent/connect_test.rb +88 -83
  49. data/test/new_relic/agent/agent/start_test.rb +75 -80
  50. data/test/new_relic/agent/agent/start_worker_thread_test.rb +18 -18
  51. data/test/new_relic/agent/beacon_configuration_test.rb +13 -11
  52. data/test/new_relic/agent/browser_monitoring_test.rb +69 -14
  53. data/test/new_relic/agent/configuration/environment_source_test.rb +58 -0
  54. data/test/new_relic/agent/configuration/manager_test.rb +120 -0
  55. data/test/new_relic/agent/configuration/server_source_test.rb +28 -0
  56. data/test/new_relic/agent/configuration/yaml_source_test.rb +56 -0
  57. data/test/new_relic/agent/error_collector/notice_error_test.rb +63 -50
  58. data/test/new_relic/agent/error_collector_test.rb +10 -12
  59. data/test/new_relic/agent/new_relic_service_test.rb +11 -3
  60. data/test/new_relic/agent/pipe_channel_manager_test.rb +19 -16
  61. data/test/new_relic/agent/rpm_agent_test.rb +21 -19
  62. data/test/new_relic/agent/sql_sampler_test.rb +55 -56
  63. data/test/new_relic/agent/transaction_info_test.rb +45 -4
  64. data/test/new_relic/agent/transaction_sampler_test.rb +48 -44
  65. data/test/new_relic/agent_test.rb +68 -41
  66. data/test/new_relic/collection_helper_test.rb +7 -8
  67. data/test/new_relic/command/deployments_test.rb +12 -1
  68. data/test/new_relic/control/frameworks/rails_test.rb +26 -0
  69. data/test/new_relic/control/logging_methods_test.rb +77 -52
  70. data/test/new_relic/control_test.rb +103 -126
  71. data/test/new_relic/local_environment_test.rb +4 -6
  72. data/test/new_relic/rack/browser_monitoring_test.rb +4 -4
  73. data/test/new_relic/rack/developer_mode_test.rb +13 -7
  74. data/test/new_relic/transaction_sample_test.rb +8 -2
  75. data/test/script/build_test_gem.sh +9 -3
  76. data/test/script/ci.sh +13 -3
  77. data/test/test_helper.rb +9 -2
  78. data/ui/helpers/developer_mode_helper.rb +2 -7
  79. metadata +26 -11
  80. data/lib/new_relic/control/configuration.rb +0 -206
  81. data/test/new_relic/control/configuration_test.rb +0 -77
@@ -6,6 +6,7 @@ require 'zlib'
6
6
  require 'stringio'
7
7
  require 'new_relic/agent/new_relic_service'
8
8
  require 'new_relic/agent/pipe_service'
9
+ require 'new_relic/agent/configuration/manager'
9
10
 
10
11
  module NewRelic
11
12
  module Agent
@@ -15,6 +16,8 @@ module NewRelic
15
16
  # in realtime as the application runs, and periodically sends that
16
17
  # data to the NewRelic server.
17
18
  class Agent
19
+ extend NewRelic::Agent::Configuration::Instance
20
+
18
21
  def initialize
19
22
  @launch_time = Time.now
20
23
 
@@ -31,8 +34,8 @@ module NewRelic
31
34
  @forked = false
32
35
 
33
36
  # FIXME: temporary work around for RUBY-839
34
- if control.monitor_mode?
35
- @service = NewRelic::Agent::NewRelicService.new(control.license_key, control.server)
37
+ if Agent.config[:monitor_mode]
38
+ @service = NewRelic::Agent::NewRelicService.new
36
39
  end
37
40
  end
38
41
 
@@ -161,9 +164,9 @@ module NewRelic
161
164
  end
162
165
 
163
166
  # log.debug "Agent received after_fork notice in #$$: [#{control.agent_enabled?}; monitor=#{control.monitor_mode?}; connected: #{@connected.inspect}; thread=#{@worker_thread.inspect}]"
164
- return if !control.agent_enabled? or
165
- !control.monitor_mode? or
166
- @connected == false or
167
+ return if !Agent.config[:agent_enabled] ||
168
+ !Agent.config[:monitor_mode] ||
169
+ @connected == false ||
167
170
  @worker_thread && @worker_thread.alive?
168
171
 
169
172
  log.info "Starting the worker thread in #$$ after forking."
@@ -199,7 +202,7 @@ module NewRelic
199
202
  # :force_send => (true/false) # force the agent to send data
200
203
  # before shutting down
201
204
  def shutdown(options={})
202
- run_loop_before_exit = options.fetch(:force_send, false)
205
+ run_loop_before_exit = Agent.config[:force_send]
203
206
  return if not started?
204
207
  if @worker_loop
205
208
  @worker_loop.run_task if run_loop_before_exit
@@ -211,7 +214,7 @@ module NewRelic
211
214
  # if litespeed, then ignore all future SIGUSR1 - it's
212
215
  # litespeed trying to shut us down
213
216
 
214
- if control.dispatcher == :litespeed
217
+ if Agent.config[:dispatcher] == :litespeed
215
218
  Signal.trap("SIGUSR1", "IGNORE")
216
219
  Signal.trap("SIGTERM", "IGNORE")
217
220
  end
@@ -224,6 +227,10 @@ module NewRelic
224
227
  log.error e
225
228
  log.error e.backtrace.join("\n")
226
229
  end
230
+ NewRelic::Agent.config.remove_config do |config|
231
+ config.class == NewRelic::Agent::Configuration::ManualSource ||
232
+ config.class == NewRelic::Agent::Configuration::ServerSource
233
+ end
227
234
  @started = nil
228
235
  end
229
236
 
@@ -294,21 +301,21 @@ module NewRelic
294
301
  # 'agent_enabled' option (e.g. in a manual start), or
295
302
  # enabled normally through the configuration file
296
303
  def disabled?
297
- !control.agent_enabled?
304
+ !Agent.config[:agent_enabled]
298
305
  end
299
306
 
300
307
  # Logs the dispatcher to the log file to assist with
301
308
  # debugging. When no debugger is present, logs this fact to
302
309
  # assist with proper dispatcher detection
303
310
  def log_dispatcher
304
- dispatcher_name = control.dispatcher.to_s
311
+ dispatcher_name = Agent.config[:dispatcher].to_s
305
312
  return if log_if(dispatcher_name.empty?, :info, "No dispatcher detected.")
306
313
  log.info "Dispatcher: #{dispatcher_name}"
307
314
  end
308
315
 
309
316
  # Logs the configured application names
310
317
  def log_app_names
311
- log.info "Application: #{control.app_names.join(", ")}"
318
+ log.info "Application: #{Agent.config.app_names.join(", ")}"
312
319
  end
313
320
 
314
321
  # Connecting in the foreground blocks further startup of the
@@ -338,7 +345,7 @@ module NewRelic
338
345
  # behavior of at_exit blocks to make sure it runs last, by
339
346
  # doing an at_exit within an at_exit block.
340
347
  def install_exit_handler
341
- if control.send_data_on_exit && !weird_ruby?
348
+ if Agent.config[:send_data_on_exit] && !weird_ruby?
342
349
  # Our shutdown handler needs to run after other shutdown handlers
343
350
  at_exit { at_exit { shutdown } }
344
351
  end
@@ -380,13 +387,13 @@ module NewRelic
380
387
  # Warn the user if they have configured their agent not to
381
388
  # send data, that way we can see this clearly in the log file
382
389
  def monitoring?
383
- log_unless(control.monitor_mode?, :warn, "Agent configured not to send data in this environment - edit newrelic.yml to change this")
390
+ log_unless(Agent.config[:monitor_mode], :warn, "Agent configured not to send data in this environment - edit newrelic.yml to change this")
384
391
  end
385
392
 
386
393
  # Tell the user when the license key is missing so they can
387
394
  # fix it by adding it to the file
388
395
  def has_license_key?
389
- log_unless(control.license_key, :error, "No license key found. Please edit your newrelic.yml file and insert your license key.")
396
+ log_unless(Agent.config[:license_key], :error, "No license key found. Please edit your newrelic.yml file and insert your license key.")
390
397
  end
391
398
 
392
399
  # A correct license key exists and is of the proper length
@@ -397,7 +404,7 @@ module NewRelic
397
404
  # A license key is an arbitrary 40 character string,
398
405
  # usually looks something like a SHA1 hash
399
406
  def correct_license_length
400
- key = control.license_key
407
+ key = Agent.config[:license_key]
401
408
  log_unless((key.length == 40), :error, "Invalid license key: #{key}")
402
409
  end
403
410
 
@@ -405,7 +412,8 @@ module NewRelic
405
412
  # requests, we need to wait until the children are forked
406
413
  # before connecting, otherwise the parent process sends odd data
407
414
  def using_forking_dispatcher?
408
- log_if([:passenger, :unicorn].include?(control.dispatcher), :info, "Connecting workers after forking.")
415
+ log_if([:passenger, :unicorn].include?(Agent.config[:dispatcher]),
416
+ :info, "Connecting workers after forking.")
409
417
  end
410
418
 
411
419
  # Sanity-check the agent configuration and start the agent,
@@ -414,7 +422,7 @@ module NewRelic
414
422
  def check_config_and_start_agent
415
423
  return unless monitoring? && has_correct_license_key?
416
424
  return if using_forking_dispatcher?
417
- connect_in_foreground if control.sync_startup
425
+ connect_in_foreground if Agent.config[:sync_startup]
418
426
  start_worker_thread
419
427
  install_exit_handler
420
428
  end
@@ -456,7 +464,7 @@ module NewRelic
456
464
  # disable transaction sampling if disabled by the server
457
465
  # and we're not in dev mode
458
466
  def check_transaction_sampler_status
459
- if control.developer_mode? || @should_send_samples
467
+ if Agent.config[:developer_mode] || @should_send_samples
460
468
  @transaction_sampler.enable
461
469
  else
462
470
  @transaction_sampler.disable
@@ -466,7 +474,7 @@ module NewRelic
466
474
  def check_sql_sampler_status
467
475
  # disable sql sampling if disabled by the server
468
476
  # and we're not in dev mode
469
- if @sql_sampler.config.fetch('enabled', true) && ['raw', 'obfuscated'].include?(@sql_sampler.config.fetch('record_sql', 'obfuscated').to_s) && @transaction_sampler.config.fetch('enabled', true)
477
+ if Agent.config[:'slow_sql.enabled'] && ['raw', 'obfuscated'].include?(Agent.config[:'slow_sql.record_sql']) && Agent.config[:'transaction_tracer.enabled']
470
478
  @sql_sampler.enable
471
479
  else
472
480
  @sql_sampler.disable
@@ -673,15 +681,15 @@ module NewRelic
673
681
  # should debug log that fact so that debug logs include a
674
682
  # clue that token authentication is what will be used
675
683
  def log_seed_token
676
- if control.validate_seed
677
- log.debug "Connecting with validation seed/token: #{control.validate_seed}/#{control.validate_token}"
684
+ if Agent.config[:validate_seed]
685
+ log.debug "Connecting with validation seed/token: #{Agent.config[:validate_seed]}/#{Agent.config[:validate_token]}"
678
686
  end
679
687
  end
680
688
 
681
689
  # Checks whether we should send environment info, and if so,
682
690
  # returns the snapshot from the local environment
683
691
  def environment_for_connect
684
- control['send_environment_info'] != false ? control.local_env.snapshot : []
692
+ Agent.config[:send_environment_info] ? Control.instance.local_env.snapshot : []
685
693
  end
686
694
 
687
695
  # These validation settings are used for cases where a
@@ -690,8 +698,8 @@ module NewRelic
690
698
  # allowed to connect, rather than setting a unique hostname
691
699
  def validate_settings
692
700
  {
693
- :seed => control.validate_seed,
694
- :token => control.validate_token
701
+ :seed => Agent.config[:validate_seed],
702
+ :token => Agent.config[:validate_token]
695
703
  }
696
704
  end
697
705
 
@@ -701,11 +709,11 @@ module NewRelic
701
709
  {
702
710
  :pid => $$,
703
711
  :host => @local_host,
704
- :app_name => control.app_names,
712
+ :app_name => Agent.config.app_names,
705
713
  :language => 'ruby',
706
714
  :agent_version => NewRelic::VERSION::STRING,
707
715
  :environment => environment_for_connect,
708
- :settings => control.settings,
716
+ :settings => Agent.config.flattened_config,
709
717
  :validate => validate_settings
710
718
  }
711
719
  end
@@ -755,14 +763,13 @@ module NewRelic
755
763
  # Reconfigure the transaction tracer
756
764
  @transaction_sampler.configure!
757
765
  @sql_sampler.configure!
758
- @should_send_samples = @config_should_send_samples = @transaction_sampler.config.fetch('enabled', true)
759
- @should_send_random_samples = @transaction_sampler.config.fetch('random_sample', false)
766
+ @should_send_samples = @config_should_send_samples = Agent.config[:'transaction_tracer.enabled']
767
+ @should_send_random_samples = Agent.config[:'transaction_tracer.random_sample']
760
768
  set_sql_recording!
761
769
 
762
770
  # default to 2.0, string 'apdex_f' will turn into your
763
771
  # apdex * 4
764
- @slowest_transaction_threshold = @transaction_sampler.config.fetch('transaction_threshold', 2.0).to_f
765
- @slowest_transaction_threshold = apdex_f if apdex_f_threshold?
772
+ @slowest_transaction_threshold = Agent.config[:'transaction_tracer.transaction_threshold']
766
773
  end
767
774
 
768
775
  # Enables or disables the transaction tracer and sets its
@@ -771,7 +778,6 @@ module NewRelic
771
778
  def configure_transaction_tracer!(server_enabled, sample_rate)
772
779
  # Ask the server for permission to send transaction samples.
773
780
  # determined by subscription license.
774
- @transaction_sampler.config['enabled'] = server_enabled
775
781
  @sql_sampler.configure!
776
782
  @should_send_samples = @config_should_send_samples && server_enabled
777
783
 
@@ -789,15 +795,7 @@ module NewRelic
789
795
 
790
796
  # apdex_f is always 4 times the apdex_t
791
797
  def apdex_f
792
- (4 * NewRelic::Control.instance.apdex_t).to_f
793
- end
794
-
795
- # If the transaction threshold is set to the string
796
- # 'apdex_f', we use 4 times the apdex_t value to record
797
- # transactions. This gears well with using apdex since you
798
- # will attempt to send any transactions that register as 'failing'
799
- def apdex_f_threshold?
800
- @transaction_sampler.config.fetch('transaction_threshold', '') =~ /apdex_f/i
798
+ (4 * Agent.config[:apdex_t]).to_f
801
799
  end
802
800
 
803
801
  # Sets the sql recording configuration by trying to detect
@@ -805,7 +803,7 @@ module NewRelic
805
803
  # 'false', 'none', and friends. Otherwise, we accept 'raw',
806
804
  # and unrecognized values default to 'obfuscated'
807
805
  def set_sql_recording!
808
- record_sql_config = @transaction_sampler.config.fetch('record_sql', :obfuscated)
806
+ record_sql_config = Agent.config[:'transaction_tracer.record_sql']
809
807
  case record_sql_config.to_s
810
808
  when 'off'
811
809
  @record_sql = :off
@@ -828,17 +826,6 @@ module NewRelic
828
826
  log.warn("Agent is configured to send raw SQL to the service") if @record_sql == :raw
829
827
  end
830
828
 
831
- # Asks the collector to tell us which sub-collector we
832
- # should be reporting to, and then does the name resolution
833
- # on that host so we don't block on DNS during the normal
834
- # course of agent processing
835
- # def set_collector_host!
836
- # host = invoke_remote(:get_redirect_host)
837
- # if host
838
- # @collector = control.server_from_host(host)
839
- # end
840
- # end
841
-
842
829
  # Sets the collector host and connects to the server, then
843
830
  # invokes the final configuration with the returned data
844
831
  def query_server_for_configuration
@@ -854,20 +841,21 @@ module NewRelic
854
841
  # ignored unless we say to do something with it here.
855
842
  def finish_setup(config_data)
856
843
  return if config_data == nil
857
- @service.agent_id = config_data['agent_run_id']
844
+
845
+ @service.agent_id = config_data['agent_run_id'] if @service
858
846
  @report_period = config_data['data_report_period']
859
847
  @url_rules = config_data['url_rules']
860
848
  @beacon_configuration = BeaconConfiguration.new(config_data)
861
- @server_side_config_enabled = config_data['listen_to_server_config']
862
849
 
863
- if @server_side_config_enabled
850
+ if config_data['listen_to_server_config']
864
851
  log.info "Using config from server"
865
852
  log.debug "Server provided config: #{config_data.inspect}"
853
+ server_config = NewRelic::Agent::Configuration::ServerSource.new(config_data)
854
+ Agent.config.apply_config(server_config, 1)
866
855
  end
867
856
 
868
- control.merge_server_side_config(config_data) if @server_side_config_enabled
869
857
  config_transaction_tracer
870
- log_connection!(config_data)
858
+ log_connection!(config_data) if @service
871
859
  configure_transaction_tracer!(config_data['collect_traces'], config_data['sample_rate'])
872
860
  configure_error_collector!(config_data['collect_errors'])
873
861
  end
@@ -63,7 +63,7 @@ module NewRelic
63
63
  def license_bytes
64
64
  if @license_bytes.nil?
65
65
  @license_bytes = []
66
- NewRelic::Control.instance.license_key.each_byte {|byte| @license_bytes << byte}
66
+ Agent.config[:license_key].each_byte {|byte| @license_bytes << byte}
67
67
  end
68
68
  @license_bytes
69
69
  end
@@ -34,8 +34,12 @@ module NewRelic
34
34
  # page as is reasonably possible - that is, before any style or
35
35
  # javascript inclusions, but after any header-related meta tags
36
36
  def browser_timing_header
37
- return "" if NewRelic::Agent.instance.beacon_configuration.nil?
38
- return "" if !NewRelic::Agent.is_transaction_traced? || !NewRelic::Agent.is_execution_traced?
37
+ if NewRelic::Agent.instance.beacon_configuration.nil? ||
38
+ !NewRelic::Agent.is_transaction_traced? ||
39
+ !NewRelic::Agent.is_execution_traced? ||
40
+ NewRelic::Agent::TransactionInfo.get.ignore_end_user?
41
+ return ""
42
+ end
39
43
 
40
44
  NewRelic::Agent.instance.beacon_configuration.browser_timing_header
41
45
  end
@@ -50,11 +54,82 @@ module NewRelic
50
54
  # page as is reasonably possible.
51
55
  def browser_timing_footer
52
56
  config = NewRelic::Agent.instance.beacon_configuration
53
- return "" if config.nil? || !config.rum_enabled || config.browser_monitoring_key.nil?
54
- return "" if !NewRelic::Agent.is_transaction_traced? || !NewRelic::Agent.is_execution_traced?
57
+
58
+ if config.nil? ||
59
+ !config.rum_enabled ||
60
+ config.browser_monitoring_key.nil? ||
61
+ !NewRelic::Agent.is_transaction_traced? ||
62
+ !NewRelic::Agent.is_execution_traced? ||
63
+ NewRelic::Agent::TransactionInfo.get.ignore_end_user?
64
+ return ""
65
+ end
66
+
55
67
  generate_footer_js(config)
56
68
  end
57
69
 
70
+ module_function
71
+
72
+ def obfuscate(config, text)
73
+ obfuscated = ""
74
+ key_bytes = config.license_bytes
75
+ index = 0
76
+ text.each_byte{|byte|
77
+ obfuscated.concat((byte ^ key_bytes[index % 13].to_i))
78
+ index+=1
79
+ }
80
+
81
+ [obfuscated].pack("m0").gsub("\n", '')
82
+ end
83
+
84
+ def browser_monitoring_transaction_name
85
+ NewRelic::Agent::TransactionInfo.get.transaction_name
86
+ end
87
+
88
+ def browser_monitoring_queue_time
89
+ clamp_to_positive((current_metric_frame.queue_time.to_f * 1000.0).round)
90
+ end
91
+
92
+ def browser_monitoring_app_time
93
+ clamp_to_positive(((Time.now - browser_monitoring_start_time).to_f * 1000.0).round)
94
+ end
95
+
96
+ def current_metric_frame
97
+ Thread.current[:last_metric_frame] || @@dummy_metric_frame
98
+ end
99
+
100
+ def clamp_to_positive(value)
101
+ return 0.0 if value < 0
102
+ value
103
+ end
104
+
105
+ def browser_monitoring_start_time
106
+ NewRelic::Agent::TransactionInfo.get.start_time
107
+ end
108
+
109
+ def insert_mobile_response_header(request, response)
110
+ if mobile_header_found_in?(request) &&
111
+ NewRelic::Agent.instance.beacon_configuration
112
+
113
+ config = NewRelic::Agent.instance.beacon_configuration
114
+
115
+ response['X-NewRelic-Beacon-Url'] = beacon_url(request)
116
+
117
+ payload = %[ ["#{config.application_id}","#{obfuscate(config, browser_monitoring_transaction_name)}",#{browser_monitoring_queue_time},#{browser_monitoring_app_time}] ]
118
+ response['X-NewRelic-App-Server-Metrics'] = payload
119
+ end
120
+ end
121
+
122
+ def mobile_header_found_in?(request)
123
+ headers = ['HTTP_X_NEWRELIC_MOBILE_TRACE', 'X_NEWRELIC_MOBILE_TRACE',
124
+ 'X-NewRelic-Mobile-Trace']
125
+ headers.inject(false){|i,m| i || (request.env[m] == 'true')}
126
+ end
127
+
128
+ def beacon_url(request)
129
+ config = NewRelic::Agent.instance.beacon_configuration
130
+ "#{request.scheme || 'http'}://#{config.beacon}/mobile/1/#{config.browser_monitoring_key}"
131
+ end
132
+
58
133
  private
59
134
 
60
135
  def generate_footer_js(config)
@@ -68,23 +143,11 @@ module NewRelic
68
143
  ''
69
144
  end
70
145
  end
71
-
72
- def browser_monitoring_transaction_name
73
- NewRelic::Agent::TransactionInfo.get.transaction_name
74
- end
75
-
76
- def browser_monitoring_start_time
77
- NewRelic::Agent::TransactionInfo.get.start_time
78
- end
79
146
 
80
147
  def metric_frame_attribute(key)
81
148
  current_metric_frame.user_attributes[key] || ""
82
149
  end
83
-
84
- def current_metric_frame
85
- Thread.current[:last_metric_frame] || @@dummy_metric_frame
86
- end
87
-
150
+
88
151
  def tt_guid
89
152
  txn = NewRelic::Agent::TransactionInfo.get
90
153
  return txn.guid if txn.include_guid?
@@ -95,19 +158,6 @@ module NewRelic
95
158
  return NewRelic::Agent::TransactionInfo.get.token
96
159
  end
97
160
 
98
- def clamp_to_positive(value)
99
- return 0.0 if value < 0
100
- value
101
- end
102
-
103
- def browser_monitoring_app_time
104
- clamp_to_positive(((Time.now - browser_monitoring_start_time).to_f * 1000.0).round)
105
- end
106
-
107
- def browser_monitoring_queue_time
108
- clamp_to_positive((current_metric_frame.queue_time.to_f * 1000.0).round)
109
- end
110
-
111
161
  def footer_js_string(config, beacon, license_key, application_id)
112
162
  obfuscated_transaction_name = obfuscate(config, browser_monitoring_transaction_name)
113
163
 
@@ -125,18 +175,6 @@ module NewRelic
125
175
  string
126
176
  end
127
177
  end
128
-
129
- def obfuscate(config, text)
130
- obfuscated = ""
131
- key_bytes = config.license_bytes
132
- index = 0
133
- text.each_byte{|byte|
134
- obfuscated.concat((byte ^ key_bytes[index % 13].to_i))
135
- index+=1
136
- }
137
-
138
- [obfuscated].pack("m0").gsub("\n", '')
139
- end
140
178
  end
141
179
  end
142
180
  end