Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve testing server debug shim #1255

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/specs/util/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ export function decodeAttributes (attributes) {
return decodedObj
}

export async function getDebugLogs () {
return browser.execute(function () {
return window.NRDEBUG_LOGS
})
}

export async function clearDebugLogs () {
return browser.execute(function () {
window.NRDEBUG_LOGS = []
})
}

export function srConfig (initOverrides = {}) {
return deepmerge(
{
Expand Down
36 changes: 14 additions & 22 deletions tools/testing-server/plugins/agent-injector/debug-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,50 @@
* EXCMAScript standards.
*/
module.exports = `
;window.NRDEBUG_LOGS=[]
;window.NRDEBUG = (function() {
var count = 0;
var id = Math.random().toString(36).substring(7);
return nrdebug;
function nrdebug(msg, sync) {
function nrdebug(msg, method) {
count++;
if (typeof msg === 'object') {
msg = JSON.stringify(msg)
}
var url = 'http://' + NREUM.info.beacon + '/debug?m=' + escape(msg) + '&testId=' + NREUM.info.licenseKey + '&r=' + Math.random() + '&ix=' + count
if (!sync) {
var img = new window.Image()
img.src = url
return img
} else {
var request = new XMLHttpRequest()
request.open('POST', url, false)
request.setRequestHeader('content-type', 'text/plain')
request.send()
}
window.NRDEBUG_LOGS.push({id, timestamp: performance?.now(), msg, url: window?.location?.href, method});
};
})()
var origOnError = window.onerror
window.onerror = function() {
NRDEBUG('error thrown: ' + JSON.stringify(arguments))
window.onerror = function(...args) {
NRDEBUG(args, 'window.onerror')
if (typeof origOnError === 'function') {
origOnError(arguments)
}
}
var origLog = window.console.log.bind(window.console)
window.console.log = function() {
NRDEBUG('console.log: ' + JSON.stringify(arguments))
window.console.log = function(...args) {
NRDEBUG(args, 'console.log')
if (typeof origLog === 'function') {
origLog(arguments)
}
}
var origWarn = window.console.warn.bind(window.console)
window.console.warn = function() {
NRDEBUG('console.warn: ' + JSON.stringify(arguments))
window.console.warn = function(...args) {
NRDEBUG(args, 'console.warn')
if (typeof origWarn === 'function') {
//origWarn(arguments)
}
}
var origErr = window.console.error.bind(window.console)
window.console.error = function() {
NRDEBUG('console.error: ' + JSON.stringify(arguments))
window.console.error = function(...args) {
NRDEBUG(args, 'console.error')
if (typeof origErr === 'function') {
origErr(arguments)
}
}
var origTrace = window.console.trace.bind(window.console)
window.console.trace = function() {
NRDEBUG('console.trace: ' + JSON.stringify(arguments))
window.console.trace = function(...args) {
NRDEBUG(args, 'console.trace')
if (typeof origTrace === 'function') {
origTrace(arguments)
}
Expand Down
Loading