Module: NewRelic::Agent::BrowserMonitoring
- Included in:
- Agent
- Defined in:
- lib/new_relic/agent/browser_monitoring.rb
Overview
This module contains support for Real User Monitoring - the javascript generation and configuration
Defined Under Namespace
Classes: DummyMetricFrame
Constant Summary
collapse
- @@dummy_metric_frame =
DummyMetricFrame.new
Class Method Summary
collapse
Instance Method Summary
collapse
-
#browser_timing_footer ⇒ Object
This method returns a string suitable for inclusion in a page - known as ‘manual instrumentation’ for Real User Monitoring.
-
#browser_timing_header ⇒ Object
This method returns a string suitable for inclusion in a page - known as ‘manual instrumentation’ for Real User Monitoring.
Class Method Details
.beacon_url(request) ⇒ Object
121
122
123
|
# File 'lib/new_relic/agent/browser_monitoring.rb', line 121
def beacon_url(request)
"#{request.scheme || 'http'}://#{Agent.config[:beacon]}/mobile/1/#{Agent.config[:browser_key]}"
end
|
.browser_monitoring_app_time ⇒ Object
79
80
81
|
# File 'lib/new_relic/agent/browser_monitoring.rb', line 79
def browser_monitoring_app_time
clamp_to_positive(((Time.now - browser_monitoring_start_time).to_f * 1000.0).round)
end
|
.browser_monitoring_queue_time ⇒ Object
75
76
77
|
# File 'lib/new_relic/agent/browser_monitoring.rb', line 75
def browser_monitoring_queue_time
clamp_to_positive((current_metric_frame.queue_time.to_f * 1000.0).round)
end
|
.browser_monitoring_start_time ⇒ Object
.browser_monitoring_transaction_name ⇒ Object
71
72
73
|
# File 'lib/new_relic/agent/browser_monitoring.rb', line 71
def browser_monitoring_transaction_name
NewRelic::Agent::TransactionInfo.get.transaction_name
end
|
.clamp_to_positive(value) ⇒ Object
87
88
89
90
|
# File 'lib/new_relic/agent/browser_monitoring.rb', line 87
def clamp_to_positive(value)
return 0.0 if value < 0
value
end
|
.current_metric_frame ⇒ Object
83
84
85
|
# File 'lib/new_relic/agent/browser_monitoring.rb', line 83
def current_metric_frame
Thread.current[:last_metric_frame] || @@dummy_metric_frame
end
|
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/new_relic/agent/browser_monitoring.rb', line 102
def (request, response)
if (request) &&
NewRelic::Agent.instance.beacon_configuration
config = NewRelic::Agent.instance.beacon_configuration
response['X-NewRelic-Beacon-Url'] = beacon_url(request)
payload = %[ ["#{Agent.config[:application_id]}","#{obfuscate(config, browser_monitoring_transaction_name)}",#{browser_monitoring_queue_time},#{browser_monitoring_app_time}] ]
response['X-NewRelic-App-Server-Metrics'] = payload
end
end
|
115
116
117
118
119
|
# File 'lib/new_relic/agent/browser_monitoring.rb', line 115
def (request)
= ['HTTP_X_NEWRELIC_MOBILE_TRACE', 'X_NEWRELIC_MOBILE_TRACE',
'X-NewRelic-Mobile-Trace']
.inject(false){|i,m| i || (request.env[m] == 'true')}
end
|
.obfuscate(config, text) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/new_relic/agent/browser_monitoring.rb', line 59
def obfuscate(config, text)
obfuscated = ""
key_bytes = config.license_bytes
index = 0
text.each_byte{|byte|
obfuscated.concat((byte ^ key_bytes[index % 13].to_i))
index+=1
}
[obfuscated].pack("m0").gsub("\n", '')
end
|
Instance Method Details
This method returns a string suitable for inclusion in a page
Monitoring. Can return either a script tag with associated javascript, or in the case of disabled Real User Monitoring, an empty string
This is the footer string - it should be placed as low in the page as is reasonably possible.
49
50
51
52
53
54
55
|
# File 'lib/new_relic/agent/browser_monitoring.rb', line 49
def
if insert_js?
(NewRelic::Agent.instance.beacon_configuration)
else
""
end
end
|
This method returns a string suitable for inclusion in a page
Monitoring. Can return either a script tag with associated javascript, or in the case of disabled Real User Monitoring, an empty string
This is the header string - it should be placed as high in the page as is reasonably possible - that is, before any style or javascript inclusions, but after any header-related meta tags
33
34
35
36
37
38
39
|
# File 'lib/new_relic/agent/browser_monitoring.rb', line 33
def
if insert_js?
NewRelic::Agent.instance.beacon_configuration.
else
""
end
end
|