-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REPLAY] Improve subdomain handling in replay link
- Loading branch information
1 parent
1635224
commit f37d429
Showing
8 changed files
with
103 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type { RumConfiguration, ViewContexts } from '@datadog/browser-rum-core' | ||
import { createRumSessionManagerMock } from '../../../rum-core/test/mockRumSessionManager' | ||
import { getSessionReplayLink } from './getSessionReplayLink' | ||
|
||
const DEFAULT_CONFIGURATION = { | ||
site: 'datad0g.com', | ||
} as RumConfiguration | ||
|
||
describe('getReplayLink', () => { | ||
it('should return undefined if there is no session', () => { | ||
const sessionManager = createRumSessionManagerMock().setNotTracked() | ||
const viewContexts = {} as ViewContexts | ||
|
||
const link = getSessionReplayLink(DEFAULT_CONFIGURATION, sessionManager, viewContexts, 'app') | ||
|
||
expect(link).toBeUndefined() | ||
}) | ||
|
||
it('should return url without query param if no view', () => { | ||
const sessionManager = createRumSessionManagerMock().setId('session-id-1') | ||
const viewContexts = { findView: () => undefined } as ViewContexts | ||
|
||
const link = getSessionReplayLink(DEFAULT_CONFIGURATION, sessionManager, viewContexts, 'app') | ||
|
||
expect(link).toBe('https://app.datad0g.com/rum/replay/sessions/session-id-1') | ||
}) | ||
|
||
const parameters: Array<[string, string | undefined, string]> = [ | ||
['datadoghq.com', undefined, 'app.datadoghq.com'], | ||
['datadoghq.com', 'toto', 'toto.datadoghq.com'], | ||
['datad0g.com', undefined, 'dd.datad0g.com'], | ||
['datad0g.com', 'toto', 'toto.datad0g.com'], | ||
['us3.datadoghq.com', undefined, 'us3.datadoghq.com'], | ||
['us3.datadoghq.com', 'toto', 'toto.us3.datadoghq.com'], | ||
['us5.datadoghq.com', undefined, 'us5.datadoghq.com'], | ||
['us5.datadoghq.com', 'toto', 'toto.us5.datadoghq.com'], | ||
] | ||
|
||
parameters.forEach(([site, subdomain, host]) => { | ||
it(`should return ${host} for subdomain "${ | ||
subdomain ?? 'undefined' | ||
}" on "${site}" with query params if view is found`, () => { | ||
const sessionManager = createRumSessionManagerMock().setId('session-id-1') | ||
const viewContexts = { | ||
findView: () => ({ | ||
id: 'view-id-1', | ||
startClocks: { | ||
timeStamp: 123456, | ||
}, | ||
}), | ||
} as ViewContexts | ||
|
||
const link = getSessionReplayLink({ ...DEFAULT_CONFIGURATION, site }, sessionManager, viewContexts, subdomain) | ||
|
||
expect(link).toBe(`https://${host}/rum/replay/sessions/session-id-1?seed=view-id-1&from=123456`) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { RumConfiguration, RumSessionManager, ViewContexts } from '@datadog/browser-rum-core' | ||
|
||
export function getSessionReplayLink( | ||
configuration: RumConfiguration, | ||
sessionManager: RumSessionManager, | ||
viewContexts: ViewContexts, | ||
subdomain = getDefaultSubdomain(configuration) | ||
): string | undefined { | ||
const site = configuration.site | ||
const session = sessionManager.findTrackedSession() | ||
if (!session) { | ||
return undefined | ||
} | ||
const sessionId = session.id | ||
const view = viewContexts.findView() | ||
const url = `https://${subdomain ? `${subdomain}.` : ''}${site}/rum/replay/sessions/${sessionId}` | ||
if (!view) { | ||
return url | ||
} | ||
return `${url}?seed=${view.id}&from=${view.startClocks.timeStamp}` | ||
} | ||
|
||
function getDefaultSubdomain(configuration: RumConfiguration): string | undefined { | ||
switch (configuration.site) { | ||
case 'datadoghq.com': | ||
return 'app' | ||
case 'datadoghq.eu': | ||
return 'app' | ||
case 'datad0g.com': | ||
return 'dd' | ||
default: | ||
return undefined | ||
} | ||
} |