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

feat: Add error mode to session trace - NEWRELIC-8666 NEWRELIC-9283 #583

Merged
merged 11 commits into from
Jun 20, 2023
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/common/session/session-entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export class SessionEntity {
this.sync(data) // update the parent class "state" properties with the local storage values
//
// TODO - compression would need happen here if we decide to do it
this.storage.set(this.lookupKey, stringify(data))
this.storage.set(this.lookupKey, stringify(this.state))
return data
} catch (e) {
// storage is inaccessible
Expand Down
2 changes: 1 addition & 1 deletion src/common/timer/interaction-timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export class InteractionTimer extends Timer {
if (state === 'hidden') this.pause()
// vis change --> visible is treated like a new interaction with the page
else {
this.onResume()
this.refresh()
this.onResume() // emit resume event after state updated
}
}, false, false, this.abortController?.signal)
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/wrap/wrap-raf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
/**
* @file Wraps `window.requestAnimationFrame` for instrumentation.
* This module is used by: jserror, session_trace.
* This module is used by: jserror.
*/

import { ee as baseEE } from '../event-emitter/contextual-ee'
Expand Down
2 changes: 1 addition & 1 deletion src/common/wrap/wrap-timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
/**
* @file Wraps native timeout and interval methods for instrumentation.
* This module is used by: jserrors, session_trace, spa.
* This module is used by: jserrors, spa.
*/

import { ee as baseEE } from '../event-emitter/contextual-ee'
Expand Down
1 change: 1 addition & 0 deletions src/features/session_replay/aggregate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ export class Aggregate extends AggregateBase {
abort () {
this.blocked = true
this.stopRecording()
this.ee.emit('REPLAY_ABORTED')
const { session } = getRuntime(this.agentIdentifier)
session.state.sessionReplay = this.mode
}
Expand Down
210 changes: 134 additions & 76 deletions src/features/session_trace/aggregate/index.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/features/session_trace/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ export const START = '-start'
export const END = '-end'
export const FN_START = 'fn' + START
export const FN_END = 'fn' + END
export const BST_TIMER = 'bstTimer'
export const PUSH_STATE = 'pushState'
21 changes: 2 additions & 19 deletions src/features/session_trace/instrument/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { handle } from '../../../common/event-emitter/handle'
import { wrapHistory, wrapEvents, wrapTimer, wrapRaf } from '../../../common/wrap'
import { wrapHistory, wrapEvents } from '../../../common/wrap'
import { now } from '../../../common/timing/now'
import { InstrumentBase } from '../../utils/instrument-base'
import * as CONSTANTS from '../constants'
import { FEATURE_NAMES } from '../../../loaders/features/features'
import { isBrowserScope } from '../../../common/util/global-scope'

const {
BST_RESOURCE, RESOURCE, BST_TIMER, START, END, FEATURE_NAME, FN_END, FN_START, PUSH_STATE
BST_RESOURCE, RESOURCE, START, END, FEATURE_NAME, FN_END, FN_START, PUSH_STATE
} = CONSTANTS

export class Instrument extends InstrumentBase {
Expand All @@ -21,8 +21,6 @@ export class Instrument extends InstrumentBase {
if (!isBrowserScope) return // session traces not supported outside web env

const thisInstrumentEE = this.ee
this.timerEE = wrapTimer(thisInstrumentEE)
this.rafEE = wrapRaf(thisInstrumentEE)
wrapHistory(thisInstrumentEE)
this.eventsEE = wrapEvents(thisInstrumentEE)

Expand All @@ -35,21 +33,6 @@ export class Instrument extends InstrumentBase {
handle('bst', [args[0], target, this.bstStart, now()], undefined, FEATURE_NAMES.sessionTrace, thisInstrumentEE)
})

this.timerEE.on(FN_START, function (args, obj, type) {
this.bstStart = now()
this.bstType = type
})
this.timerEE.on(FN_END, function (args, target) {
handle(BST_TIMER, [target, this.bstStart, now(), this.bstType], undefined, FEATURE_NAMES.sessionTrace, thisInstrumentEE)
})

this.rafEE.on(FN_START, function () {
this.bstStart = now()
})
this.rafEE.on(FN_END, function (args, target) {
handle(BST_TIMER, [target, this.bstStart, now(), 'requestAnimationFrame'], undefined, FEATURE_NAMES.sessionTrace, thisInstrumentEE)
})

thisInstrumentEE.on(PUSH_STATE + START, function (args) {
this.time = now()
this.startPath = location.pathname + location.hash
Expand Down
26 changes: 0 additions & 26 deletions tests/assets/click.html

This file was deleted.

4 changes: 2 additions & 2 deletions tests/assets/stn/ajax-disabled.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
// we need to have >30 nodes in the session trace to ensure it actually gets
// sent, so make some nodes
function generateNodes() {
for (var i = 0; i < 31; i++) {
setTimeout(function () {}, 0)
for (var i = 0; i < 30; i++) {
window.history.pushState({},"")
}
}
</script>
Expand Down
27 changes: 1 addition & 26 deletions tests/browser/stn/stn.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,14 @@ function runTests () {

test('wait for trace node generation', function (t) {
ee.emit('feat-err', [])
t.plan(4)
t.plan(3) // test will wait until all 3 t.ok from below are seen!
window.history.pushState(null, '', '#foo')
window.history.pushState(null, '', '#bar')
setTimeout(() => t.ok(true), 0)
let interval = setInterval(() => {
clearInterval(interval)
t.ok(true)
}, 0)
window.requestAnimationFrame(() => {
t.ok(true)
throw new Error('raf error')
})
let xhr = new XMLHttpRequest()
xhr.open('GET', window.location)
xhr.send()
Expand Down Expand Up @@ -99,27 +95,6 @@ function runTests () {
t.equal(node.o, 'document', 'load node origin ' + node.o)
t.end()
})
t.test('stn timer', function (t) {
let node = res.filter(function (node) { return node.n === 'setInterval' })[0]
t.ok(node, 'timer node created')
t.ok(node.s > 10, 'timer node has start time ' + node.s)
t.equal(node.o, 'window', 'setInterval origin ' + node.o)
t.end()
})
t.test('stn-raf', function (t) {
let node = res.filter(function (node) { return node.n === 'requestAnimationFrame' })[0]
t.ok(node, 'raf node created')
t.ok(node.s > 10, 'raf node has start time ' + node.s)
t.equal(node.o, 'window', 'requestAnimationFrame origin ' + node.o)
t.end()
})
t.test('stn error', function (t) {
let errorNode = res.filter(function (node) { return node.o === 'raf error' })[0]
t.ok(errorNode, 'error node created')
t.ok(errorNode.s > 10, 'error node has start time ' + errorNode.s)
t.equal(errorNode.s, errorNode.e, 'error node has no duration')
t.end()
})
t.test('stn ajax', function (t) {
let ajax = res.filter(function (node) { return node.t === 'ajax' })[0]
t.ok(ajax, 'ajax node created')
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/stn/ajax.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ testDriver.test('session trace resources', supported, function (t, browser, rout
.elementByCssSelector('body')
.click()

resourcePromise = router.expectResources()
resourcePromise = router.expectResources(7000)

return Promise.all([resourcePromise, clickPromise])
})
Expand Down Expand Up @@ -89,7 +89,7 @@ testDriver.test('session trace ajax deny list', supported, function (t, browser,
.elementByCssSelector('body')
.click()

resourcePromise = router.expectResources()
resourcePromise = router.expectResources(7000)

return Promise.all([resourcePromise, clickPromise])
})
Expand Down
28 changes: 0 additions & 28 deletions tests/functional/stn/event-overwritten.test.js

This file was deleted.

1 change: 0 additions & 1 deletion tests/functional/stn/harvest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ testDriver.test('session traces are retried when collector returns 429 during sc

let thirdBody = result.request.body

t.ok(secondBody.res.length > firstBody.res.length, 'second try has more nodes than first')
t.ok(containsAll(thirdBody, secondBody), 'all nodes have been resent')

// this is really checking that no nodes have been resent
Expand Down