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

🐛[RUMF-900] prevent events to be sent from expired session #814

Merged
merged 3 commits into from
Apr 29, 2021
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: 11 additions & 1 deletion packages/rum-core/src/domain/assembly.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ describe('rum assembly', () => {
expect(serverRumEvents.length).toBe(0)
})

it('when view context has session id, it should generate event', () => {
it('when view context has current session id, it should generate event', () => {
viewSessionId = '1234'

lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
Expand All @@ -337,6 +337,16 @@ describe('rum assembly', () => {
expect(serverRumEvents.length).toBe(1)
})

it('when view context has not the current session id, it should not generate event', () => {
viewSessionId = '6789'

lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0 as RelativeTime,
})
expect(serverRumEvents.length).toBe(0)
})

it('when view context has no session id, it should not generate event', () => {
viewSessionId = undefined

Expand Down
2 changes: 1 addition & 1 deletion packages/rum-core/src/domain/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function startRumAssembly(
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
({ startTime, rawRumEvent, savedCommonContext, customerContext }) => {
const viewContext = parentContexts.findView(startTime)
if (session.isTracked() && viewContext && viewContext.session.id) {
if (session.isTracked() && viewContext && viewContext.session.id === session.getId()) {
const actionContext = parentContexts.findAction(startTime)
const commonContext = savedCommonContext || getCommonContext()
const rumContext: RumContext = {
Expand Down
5 changes: 5 additions & 0 deletions packages/rum-recorder/src/boot/recorder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ describe('startRecording', () => {
}
},
})
.withSession({
getId: () => sessionId,
isTracked: () => true,
isTrackedWithResource: () => true,
})
.beforeBuild(({ lifeCycle, applicationId, configuration, parentContexts, session }) =>
startRecording(lifeCycle, applicationId, configuration, session, parentContexts)
)
Expand Down
15 changes: 14 additions & 1 deletion packages/rum-recorder/src/domain/segmentCollection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ describe('computeSegmentContext', () => {
}

const DEFAULT_SESSION: RumSession = {
getId: () => 'session-id',
getId: () => '456',
isTracked: () => true,
isTrackedWithResource: () => true,
}
Expand Down Expand Up @@ -243,6 +243,19 @@ describe('computeSegmentContext', () => {
).toBeUndefined()
})

it('returns undefined if the session id is not the one of the current session', () => {
expect(
computeSegmentContext(
'appid',
DEFAULT_SESSION,
mockParentContexts({
...DEFAULT_VIEW_CONTEXT,
session: { id: 'expired-session' },
})
)
).toBeUndefined()
})

it('returns undefined if the session is not tracked', () => {
expect(
computeSegmentContext(
Expand Down
2 changes: 1 addition & 1 deletion packages/rum-recorder/src/domain/segmentCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export function computeSegmentContext(applicationId: string, session: RumSession
return undefined
}
const viewContext = parentContexts.findView()
if (!viewContext?.session.id) {
if (!viewContext?.session.id || viewContext.session.id !== session.getId()) {
bcaudan marked this conversation as resolved.
Show resolved Hide resolved
return undefined
}
return {
Expand Down