Skip to content

fix: Capture potential missing tail data for session trace #624

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

Merged
merged 5 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 6 additions & 6 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion src/common/harvest/harvest.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export class Harvest extends SharedContext {
sendX (spec = {}) {
const submitMethod = submitData.getSubmitMethod({ isFinalHarvest: spec.opts?.unload })
const options = {
retry: !spec.opts?.unload && submitMethod === submitData.xhr
retry: !spec.opts?.unload && submitMethod === submitData.xhr,
isFinalHarvest: spec.opts?.unload === true
}
const payload = this.createPayload(spec.endpoint, options)
const caller = this.obfuscator.shouldObfuscate() ? this.obfuscateAndSend.bind(this) : this._send.bind(this)
Expand Down
2 changes: 1 addition & 1 deletion src/common/harvest/harvest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('sendX', () => {

harvestInstance.sendX(spec)

expect(harvestInstance.createPayload).toHaveBeenCalledWith(spec.endpoint, { retry: true })
expect(harvestInstance.createPayload).toHaveBeenCalledWith(spec.endpoint, { retry: true, isFinalHarvest: false })
})

test('should not use obfuscateAndSend', async () => {
Expand Down
22 changes: 13 additions & 9 deletions src/features/session_trace/aggregate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export class Aggregate extends AggregateBase {
this.sentTrace = null
this.harvestTimeSeconds = getConfigurationValue(agentIdentifier, 'session_trace.harvestTimeSeconds') || 10
this.maxNodesPerHarvest = getConfigurationValue(agentIdentifier, 'session_trace.maxNodesPerHarvest') || 1000
/**
* Standalone (mode) refers to the legacy version of ST before the idea of 'session' or the Replay feature existed.
* It has some different behavior vs when used in tandem with replay. */
this.isStandalone = false
const operationalGate = new HandlerCache() // acts as a controller-intermediary that can enable or disable this feature's collection dynamically
const sessionEntity = this.agentRuntime.session
Expand Down Expand Up @@ -145,6 +148,14 @@ export class Aggregate extends AggregateBase {
}
/* --- EoS --- */

setTimeout(() => {
if (this.isStandalone) { // hard stop Trace after this time, sending out whatever's buffered
operationalGate.permanentlyDecide(false)
this.#scheduler.runHarvest({ unload: true }) // this is ran like the final harvest so that even if there isn't enough nodeCount, it'll still send
this.#scheduler.stopTimer(true)
}
}, MAX_TRACE_DURATION)

// register the handlers immediately... but let the handlerCache decide if the data should actually get stored...
registerHandler('bst', (...args) => operationalGate.settle(() => this.storeEvent(...args)), this.featureName, this.ee)
registerHandler('bstResource', (...args) => operationalGate.settle(() => this.storeResources(...args)), this.featureName, this.ee)
Expand Down Expand Up @@ -190,16 +201,9 @@ export class Aggregate extends AggregateBase {
}

#prepareHarvest (options) {
/* Standalone refers to the legacy version of ST before the idea of 'session' or the Replay feature existed.
It has a different behavior on returning a payload for harvest than when used in tandem with either of those concepts. */
if (this.isStandalone) {
if (now() > MAX_TRACE_DURATION) { // been collecting for over the longest duration we should run for, empty trace object so ST has nothing to send
this.#scheduler.stopTimer()
this.trace = {}
return
}
// Only harvest when more than some threshold of nodes are pending, after the very first harvest.
if (this.ptid && this.nodeCount <= REQ_THRESHOLD_TO_SEND) return
// Only harvest when more than some threshold of nodes are pending, after the very first harvest, with the exception of the last outgoing harvest.
if (this.ptid && this.nodeCount <= REQ_THRESHOLD_TO_SEND && !options.isFinalHarvest) return
} else {
// -- *cli May '26 - Update: Not rate limiting backgrounded pages either for now.
// if (this.ptid && document.visibilityState === 'hidden' && this.nodeCount <= REQ_THRESHOLD_TO_SEND) return
Expand Down
8 changes: 4 additions & 4 deletions tools/browsers-lists/browsers-supported.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"browserName": "chrome",
"platformName": "Windows 11",
"platform": "Windows 11",
"version": "105",
"browserVersion": "105"
"version": "106",
"browserVersion": "106"
},
{
"browserName": "chrome",
"platformName": "Windows 11",
"platform": "Windows 11",
"version": "108",
"browserVersion": "108"
"version": "109",
"browserVersion": "109"
},
{
"browserName": "chrome",
Expand Down