Skip to content

Commit

Permalink
chore: Add current url to Session Replay and Session Trace payloads (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ptang-nr authored Oct 2, 2024
1 parent 033f97a commit 1306012
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/features/session_replay/aggregate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { deregisterDrain } from '../../../common/drain/drain'
import { now } from '../../../common/timing/now'
import { buildNRMetaNode } from '../shared/utils'
import { MAX_PAYLOAD_SIZE } from '../../../common/constants/agent-constants'
import { cleanURL } from '../../../common/url/clean-url'

export class Aggregate extends AggregateBase {
static featureName = FEATURE_NAME
Expand Down Expand Up @@ -362,7 +363,8 @@ export class Aggregate extends AggregateBase {
'rrweb.version': RRWEB_VERSION,
'payload.type': recorderEvents.type,
// customer-defined data should go last so that if it exceeds the query param padding limit it will be truncated instead of important attrs
...(endUserId && { 'enduser.id': this.obfuscator.obfuscateString(endUserId) })
...(endUserId && { 'enduser.id': this.obfuscator.obfuscateString(endUserId) }),
currentUrl: this.obfuscator.obfuscateString(cleanURL('' + location))
// The Query Param is being arbitrarily limited in length here. It is also applied when estimating the size of the payload in getPayloadSize()
}, QUERY_PARAM_PADDING).substring(1) // remove the leading '&'
},
Expand Down
4 changes: 3 additions & 1 deletion src/features/session_trace/aggregate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { deregisterDrain } from '../../../common/drain/drain'
import { globalScope } from '../../../common/constants/runtime'
import { MODE, SESSION_EVENTS } from '../../../common/session/constants'
import { applyFnToProps } from '../../../common/util/traverse'
import { cleanURL } from '../../../common/url/clean-url'

const ERROR_MODE_SECONDS_WINDOW = 30 * 1000 // sliding window of nodes to track when simply monitoring (but not harvesting) in error mode
/** Reserved room for query param attrs */
Expand Down Expand Up @@ -172,7 +173,8 @@ export class Aggregate extends AggregateBase {
ptid: `${this.ptid}`,
session: `${this.sessionId}`,
// customer-defined data should go last so that if it exceeds the query param padding limit it will be truncated instead of important attrs
...(endUserId && { 'enduser.id': this.obfuscator.obfuscateString(endUserId) })
...(endUserId && { 'enduser.id': this.obfuscator.obfuscateString(endUserId) }),
currentUrl: this.obfuscator.obfuscateString(cleanURL('' + location))
// The Query Param is being arbitrarily limited in length here. It is also applied when estimating the size of the payload in getPayloadSize()
}, QUERY_PARAM_PADDING).substring(1) // remove the leading '&'
},
Expand Down
10 changes: 9 additions & 1 deletion tests/specs/session-replay/payload.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ describe('Session Replay Payload Validation', () => {
.then(() => browser.getAgentSessionInfo())
])

testExpectedReplay({ data: sessionReplayHarvest.request, session, hasError: false, hasMeta: true, hasSnapshot: true, isFirstChunk: true })
testExpectedReplay({
data: sessionReplayHarvest.request,
session,
hasError: false,
hasMeta: true,
hasSnapshot: true,
isFirstChunk: true,
currentUrl: sessionReplayHarvest.request.headers.origin + '/tests/assets/rrweb-instrumented.html'
})
})

it('should match expected payload - error', async () => {
Expand Down
9 changes: 8 additions & 1 deletion tests/specs/session-trace/payload-metadata.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ describe('STN Payload metadata checks', () => {
const firstTimestampOffset = request.body.reduce((acc, next) => (next.s < acc) ? next.s : acc, Infinity)
const lastTimestampOffset = request.body.reduce((acc, next) => (next.e > acc) ? next.e : acc, 0)
// first session harvest is not reported if session is disabled
testExpectedTrace({ data: request, nodeCount: request.body.length, firstTimestampOffset, lastTimestampOffset, firstSessionHarvest: true })
testExpectedTrace({
data: request,
nodeCount: request.body.length,
firstTimestampOffset,
lastTimestampOffset,
firstSessionHarvest: true,
currentUrl: request.headers.origin + '/tests/assets/instrumented.html'
})
})
})
9 changes: 6 additions & 3 deletions tests/specs/util/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const RRWEB_EVENT_TYPES = {
Custom: 5
}

export function testExpectedReplay ({ data, session, hasMeta, hasSnapshot, hasError, isFirstChunk, contentEncoding, decompressedBytes, appId, entityGuid, harvestId }) {
export function testExpectedReplay ({ data, session, hasMeta, hasSnapshot, hasError, isFirstChunk, contentEncoding, decompressedBytes, appId, entityGuid, harvestId, currentUrl }) {
expect(data.query).toMatchObject({
browser_monitoring_key: expect.any(String),
type: 'SessionReplay',
Expand All @@ -41,7 +41,8 @@ export function testExpectedReplay ({ data, session, hasMeta, hasSnapshot, hasEr
isFirstChunk: isFirstChunk || expect.any(Boolean),
decompressedBytes: decompressedBytes || expect.any(Number),
'rrweb.version': expect.any(String),
inlinedAllStylesheets: expect.any(Boolean)
inlinedAllStylesheets: expect.any(Boolean),
...(currentUrl && { currentUrl })
})

expect(data.body).toEqual(expect.any(Array))
Expand All @@ -57,7 +58,8 @@ export function testExpectedTrace ({
session,
ptid,
harvestId,
entityGuid
entityGuid,
currentUrl
}) {
expect(data.query).toMatchObject({
browser_monitoring_key: expect.any(String),
Expand All @@ -77,6 +79,7 @@ export function testExpectedTrace ({
'trace.nodes': nodeCount || expect.any(Number),
ptid: ptid || expect.anything(),
session: session || expect.any(String),
...(currentUrl && { currentUrl }),
// optional attrs here
...(firstSessionHarvest && { firstSessionHarvest }),
...(hasReplay && { hasReplay })
Expand Down

0 comments on commit 1306012

Please sign in to comment.