Skip to content

Commit

Permalink
🚩 add 'new-session' flag
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed Apr 7, 2020
1 parent 742d842 commit 3ac7581
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
6 changes: 5 additions & 1 deletion packages/logs/src/loggerSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ export function startLoggerSession(configuration: Configuration, areCookieAuthor
isTracked: () => isTracked,
}
}
const session = startSessionManagement(LOGGER_SESSION_KEY, (rawType) => computeSessionState(configuration, rawType))
const session = startSessionManagement(
LOGGER_SESSION_KEY,
(rawType) => computeSessionState(configuration, rawType),
configuration.isEnabled('new-session')
)
return {
getId: session.getId,
isTracked: () => session.getType() === LoggerSessionType.TRACKED,
Expand Down
7 changes: 4 additions & 3 deletions packages/logs/test/loggerSession.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { LOGGER_SESSION_KEY, LoggerSessionType, startLoggerSession } from '../sr

describe('logger session', () => {
const DURATION = 123456
const configuration: Partial<Configuration> = { sampleRate: 0.5 }
const configuration: Partial<Configuration> = { isEnabled: () => true, sampleRate: 0.5 }
let tracked = true

beforeEach(() => {
Expand All @@ -21,10 +21,11 @@ describe('logger session', () => {
})

afterEach(() => {
// remove intervals first
stopSessionManagement()
// flush pending callbacks to avoid random failures
jasmine.clock().tick(new Date().getTime())
jasmine.clock().uninstall()
stopSessionManagement()
})

it('when tracked should store session type and id', () => {
Expand Down Expand Up @@ -59,7 +60,7 @@ describe('logger session', () => {

startLoggerSession(configuration as Configuration, true)

expect(getCookie(SESSION_COOKIE_NAME)).toBe(`${LOGGER_SESSION_KEY}=${LoggerSessionType.NOT_TRACKED}`)
expect(getCookie(SESSION_COOKIE_NAME)).toContain(`${LOGGER_SESSION_KEY}=${LoggerSessionType.NOT_TRACKED}`)
})

it('should renew on activity after expiration', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/rum/src/rumSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export enum RumSessionType {
}

export function startRumSession(configuration: Configuration, lifeCycle: LifeCycle): RumSession {
const session = startSessionManagement(RUM_SESSION_KEY, (rawType) => computeSessionState(configuration, rawType))
const session = startSessionManagement(
RUM_SESSION_KEY,
(rawType) => computeSessionState(configuration, rawType),
configuration.isEnabled('new-session')
)

session.renewObservable.subscribe(() => {
lifeCycle.notify(LifeCycleEventType.SESSION_RENEWED)
Expand Down
6 changes: 4 additions & 2 deletions packages/rum/test/rumSession.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('rum session', () => {
const DURATION = 123456
const configuration: Partial<Configuration> = {
...DEFAULT_CONFIGURATION,
isEnabled: () => true,
resourceSampleRate: 0.5,
sampleRate: 0.5,
}
Expand All @@ -38,10 +39,11 @@ describe('rum session', () => {
})

afterEach(() => {
// remove intervals first
stopSessionManagement()
// flush pending callbacks to avoid random failures
jasmine.clock().tick(new Date().getTime())
jasmine.clock().uninstall()
stopSessionManagement()
})

it('when tracked with resources should store session type and id', () => {
Expand Down Expand Up @@ -90,7 +92,7 @@ describe('rum session', () => {
startRumSession(configuration as Configuration, lifeCycle)

expect(renewSessionSpy).not.toHaveBeenCalled()
expect(getCookie(SESSION_COOKIE_NAME)).toBe(`${RUM_SESSION_KEY}=${RumSessionType.NOT_TRACKED}`)
expect(getCookie(SESSION_COOKIE_NAME)).toContain(`${RUM_SESSION_KEY}=${RumSessionType.NOT_TRACKED}`)
})

it('should renew on activity after expiration', () => {
Expand Down
1 change: 1 addition & 0 deletions test/static/bundle-e2e-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
logsEndpoint: `${intakeOrigin}/logs`,
rumEndpoint: `${intakeOrigin}/rum`,
forwardErrorsToLogs: true,
enableExperimentalFeatures: ['new-session'],
})
</script>
<script type="text/javascript" src="./datadog-rum-us.js"></script>
Expand Down

0 comments on commit 3ac7581

Please sign in to comment.