Skip to content

Commit 50f4ace

Browse files
fix: Harvest first session trace payload immediately (#1483)
1 parent f944b76 commit 50f4ace

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

.github/actions/build-ab/templates/released.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ window.NREUM={
1515
harvest: {interval: 5},
1616
session_replay: {
1717
enabled: true,
18-
autoStart: false,
1918
fix_stylesheets: false,
2019
{{#if (isEnvironment args.environment 'dev' 'staging')}}
2120
mask_all_inputs: false,
2221
mask_text_selector: null,
22+
{{else}}
23+
autoStart: false,
2324
{{/if}}
2425
},
2526
session_trace: {

docs/warning-codes.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,8 @@
116116
### 57
117117
`Failed to execute measure. Arguments must have valid types.`
118118
### 58
119-
`Failed to execute measure. Resulting duration must be non-negative.`
119+
`Failed to execute measure. Resulting duration must be non-negative.`
120+
### 59
121+
`Session replay harvested before a session trace payload could be sent. This could be problematic for replays that rely on a trace`
122+
### 60
123+
`Session trace aborted`

src/common/util/console.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import { dispatchGlobalEvent } from '../dispatch/global-event'
7+
68
/* eslint no-console: ["error", { allow: ["debug"] }] */
79

810
/**
@@ -14,4 +16,15 @@
1416
export function warn (code, secondary) {
1517
if (typeof console.debug !== 'function') return
1618
console.debug(`New Relic Warning: https://github.com/newrelic/newrelic-browser-agent/blob/main/docs/warning-codes.md#${code}`, secondary)
19+
dispatchGlobalEvent({
20+
agentIdentifier: null,
21+
drained: null,
22+
type: 'data',
23+
name: 'warn',
24+
feature: 'warn',
25+
data: {
26+
code,
27+
secondary
28+
}
29+
})
1730
}

src/features/session_replay/aggregate/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ export class Aggregate extends AggregateBase {
262262
if (recorderEvents.type === 'preloaded') this.agentRef.runtime.harvester.triggerHarvestFor(this)
263263
payloadOutput.payload = payload
264264

265+
if (!this.agentRef.runtime.session.state.traceHarvestStarted) {
266+
warn(59, JSON.stringify(this.agentRef.runtime.session.state))
267+
}
268+
265269
return [payloadOutput]
266270
}
267271

src/features/session_trace/aggregate/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { globalScope } from '../../../common/constants/runtime'
1111
import { MODE, SESSION_EVENTS } from '../../../common/session/constants'
1212
import { applyFnToProps } from '../../../common/util/traverse'
1313
import { cleanURL } from '../../../common/url/clean-url'
14+
import { warn } from '../../../common/util/console'
1415

1516
const ERROR_MODE_SECONDS_WINDOW = 30 * 1000 // sliding window of nodes to track when simply monitoring (but not harvesting) in error mode
1617
/** Reserved room for query param attrs */
@@ -97,6 +98,8 @@ export class Aggregate extends AggregateBase {
9798
}
9899
this.agentRef.runtime.session.write({ sessionTraceMode: this.mode })
99100
this.drain()
101+
/** try to harvest immediately. This will not send if the trace is not running in FULL mode due to the pre-harvest checks. */
102+
this.agentRef.runtime.harvester.triggerHarvestFor(this)
100103
}
101104

102105
preHarvestChecks () {
@@ -178,7 +181,8 @@ export class Aggregate extends AggregateBase {
178181
}
179182

180183
/** Stop running for the remainder of the page lifecycle */
181-
abort () {
184+
abort (code) {
185+
warn(60, code)
182186
this.blocked = true
183187
this.mode = MODE.OFF
184188
this.agentRef.runtime.session.write({ sessionTraceMode: this.mode })

0 commit comments

Comments
 (0)