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

[REPLAY] Add public function to get the link to current Replay #2047

Merged
merged 25 commits into from
Apr 11, 2023

Conversation

ThibautGeriz
Copy link
Contributor

@ThibautGeriz ThibautGeriz commented Mar 1, 2023

Motivation

Add public function to get the link to current Replay

Changes

Add public function to get the link to current Replay

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@ThibautGeriz ThibautGeriz marked this pull request as ready for review March 1, 2023 14:59
@ThibautGeriz ThibautGeriz requested review from a team as code owners March 1, 2023 14:59
@codecov-commenter
Copy link

codecov-commenter commented Mar 3, 2023

Codecov Report

Merging #2047 (0333598) into main (6fae0e8) will increase coverage by 0.02%.
The diff coverage is 87.93%.

@@            Coverage Diff             @@
##             main    #2047      +/-   ##
==========================================
+ Coverage   93.60%   93.63%   +0.02%     
==========================================
  Files         192      196       +4     
  Lines        6008     6060      +52     
  Branches     1349     1362      +13     
==========================================
+ Hits         5624     5674      +50     
- Misses        384      386       +2     
Impacted Files Coverage Δ
packages/rum-core/src/domain/configuration.ts 93.87% <ø> (ø)
...kages/rum-core/src/domain/contexts/viewContexts.ts 100.00% <ø> (ø)
packages/rum-core/test/noopRecorderApi.ts 75.00% <0.00%> (-25.00%) ⬇️
packages/rum/src/boot/recorderApi.ts 90.38% <0.00%> (-5.98%) ⬇️
packages/rum-core/src/boot/rumPublicApi.ts 90.09% <50.00%> (-1.66%) ⬇️
packages/rum/src/domain/getSessionReplayLink.ts 92.85% <92.85%> (ø)
...kages/core/src/domain/configuration/intakeSites.ts 100.00% <100.00%> (ø)
...ackages/rum-core/src/domain/getSessionReplayUrl.ts 100.00% <100.00%> (ø)
...ckages/rum-slim/src/domain/getSessionReplayLink.ts 100.00% <100.00%> (ø)
packages/rum/src/boot/isBrowserSupported.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@ThibautGeriz ThibautGeriz force-pushed the thibaut.gery/add-replay-link branch from 3d7e085 to f37d429 Compare March 3, 2023 14:08
@ThibautGeriz ThibautGeriz requested review from BenoitZugmeyer and a team March 3, 2023 14:22
@ThibautGeriz ThibautGeriz changed the title [RUM][REPLAY] Add public function to get the link to current Replay [REPLAY] Add public function to get the link to current Replay Mar 3, 2023
@ThibautGeriz ThibautGeriz force-pushed the thibaut.gery/add-replay-link branch from 6ab3f76 to 9d8fb61 Compare March 20, 2023 14:45
@ThibautGeriz ThibautGeriz force-pushed the thibaut.gery/add-replay-link branch 5 times, most recently from a27afad to 3926e6b Compare April 4, 2023 07:34
@ThibautGeriz ThibautGeriz force-pushed the thibaut.gery/add-replay-link branch from 3926e6b to ee0d030 Compare April 4, 2023 07:36
Comment on lines 1 to 11
/**
* Test for Browser features used while recording
*/
export function isBrowserSupported() {
return (
// Array.from is a bit less supported by browsers than CSSSupportsRule, but has higher chances
// to be polyfilled. Test for both to be more confident. We could add more things if we find out
// this test is not sufficient.
typeof Array.from === 'function' && typeof CSSSupportsRule === 'function' && 'forEach' in NodeList.prototype
)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: extracted from recorderApi.ts to avoid a circular dep


const link = getSessionReplayLink({ ...DEFAULT_CONFIGURATION, site, subdomain }, sessionManager, viewContexts)

expect(link).toBe(`https://${host}/rum/replay/sessions/session-id-1?seed=view-id-1&from=123456`)
Copy link
Contributor Author

@ThibautGeriz ThibautGeriz Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: this one fails on the browser stack with IE because error-type=browser-not-supported gets rightfully added. Should I disable the test on IE11? Should I re-use the helper isBrowserSupported in the unit tests here? Should I mock isBrowserSupported to force it disabled on every browser?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change the expectation on IE?

Suggested change
expect(link).toBe(`https://${host}/rum/replay/sessions/session-id-1?seed=view-id-1&from=123456`)
expect(link).toBe(isIE() ? ... : `https://${host}/rum/replay/sessions/session-id-1?seed=view-id-1&from=123456`)

Copy link
Contributor Author

@ThibautGeriz ThibautGeriz Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 still breaking on chrome/android, should I use isBrowserSupported instead of isIE?
https://gitlab.ddbuild.io/DataDog/browser-sdk/-/jobs/249222844

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThibautGeriz the job is failing on IE11 no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems I cannot read apparently

packages/rum/src/domain/getSessionReplayLink.ts Outdated Show resolved Hide resolved
packages/rum/src/domain/getSessionReplayLink.ts Outdated Show resolved Hide resolved
packages/rum/src/domain/getSessionReplayLink.ts Outdated Show resolved Hide resolved
packages/rum-slim/src/domain/getSessionReplayLink.spec.ts Outdated Show resolved Hide resolved
packages/rum/src/domain/getSessionReplayLink.spec.ts Outdated Show resolved Hide resolved

const link = getSessionReplayLink({ ...DEFAULT_CONFIGURATION, site, subdomain }, sessionManager, viewContexts)

expect(link).toBe(`https://${host}/rum/replay/sessions/session-id-1?seed=view-id-1&from=123456`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change the expectation on IE?

Suggested change
expect(link).toBe(`https://${host}/rum/replay/sessions/session-id-1?seed=view-id-1&from=123456`)
expect(link).toBe(isIE() ? ... : `https://${host}/rum/replay/sessions/session-id-1?seed=view-id-1&from=123456`)

@@ -0,0 +1,20 @@
import type { RumConfiguration } from './configuration'

export function getDatadogOrigin(rumConfiguration: RumConfiguration) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 suggestion: ‏to be consistent with public docs naming

Suggested change
export function getDatadogOrigin(rumConfiguration: RumConfiguration) {
export function getDatadogSiteUrl(rumConfiguration: RumConfiguration) {

return `https://${subdomain ? `${subdomain}.` : ''}${site}`
}

function getDefaultSubdomain(configuration: RumConfiguration): string | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 suggestion: for clarity + no need to pass the whole configuration‏

Suggested change
function getDefaultSubdomain(configuration: RumConfiguration): string | undefined {
function getSiteDefaultSubdomain(site: string): string | undefined {

Comment on lines 11 to 14
case 'datadoghq.com':
return 'app'
case 'datadoghq.eu':
return 'app'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥜 nitpick:

Suggested change
case 'datadoghq.com':
return 'app'
case 'datadoghq.eu':
return 'app'
case 'datadoghq.com':
case 'datadoghq.eu':
return 'app'

Comment on lines 11 to 15
case 'datadoghq.com':
return 'app'
case 'datadoghq.eu':
return 'app'
case 'datad0g.com':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 suggestion: ‏we could use/add constants from intakeSites

export const INTAKE_SITE_STAGING = 'datad0g.com'
export const INTAKE_SITE_US1 = 'datadoghq.com'
export const INTAKE_SITE_AP1 = 'ap1.datadoghq.com'
export const INTAKE_SITE_US1_FED = 'ddog-gov.com'

it(`should return ${host} for subdomain "${
subdomain ?? 'undefined'
}" on "${site}" with query params if view is found`, () => {
const link = getDatadogOrigin({ ...DEFAULT_CONFIGURATION, site, subdomain })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 suggestion:DEFAULT_CONFIGURATION does not seem to be used

Suggested change
const link = getDatadogOrigin({ ...DEFAULT_CONFIGURATION, site, subdomain })
const link = getDatadogOrigin({ site, subdomain } as RumConfiguration)

): string | undefined {
const session = sessionManager.findTrackedSession()
const parameters: string[] = []
const sessionId = session ? session.id : 'session-id'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 suggestion: what about no-session-id for the value when there is no session id? ‏

Comment on lines 5 to 6
const origin = getDatadogOrigin(configuration)
return `${origin}/rum/replay/sessions/session-id?error-type=slim-package`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 thought: ‏it could be interesting to mutualise the building logic of the url with the rum one to avoid to forget to apply future changes here

Copy link
Contributor Author

@ThibautGeriz ThibautGeriz Apr 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like that? Where should that go? packages/rum-core/src/domain?

type QueryParams =  { errorType?: string; seed?: string; ts?: number }
function getSessionReplayUrl(configuration: RumConfiguration, { errorType, seed, ts }: QueryParams): string {
  // impl
}

we could even remove the seed & ts params and pass down the arg: ViewContexts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packages/rum-core/src/domain?

LGTM, you could probably have a single file for that and getDatadogOrigin

Comment on lines 52 to 54
if (view && !getReplayStats(view.id)) {
return 'replay-not-started'
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 suggestion: ‏what about using recorder state directly rather than accessing replay stats?

Copy link
Contributor Author

@ThibautGeriz ThibautGeriz Apr 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will leave @BenoitZugmeyer answer this one as I lack the knowledge here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good idea. You could do something like this: https://gist.github.com/BenoitZugmeyer/b0c6a09367b4a7970211cb66c7eea5d3 .

site: 'datad0g.com',
} as RumConfiguration

describe('getReplayLink', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 suggestion: ‏Could you add a test for replay-not-started?

@ThibautGeriz ThibautGeriz requested a review from bcaudan April 5, 2023 09:55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 suggestion: ‏what about renaming this file to getSessionReplayUrl?
FMU, getDatadogSiteUrl is only exposed for tests

packages/rum-core/src/index.ts Outdated Show resolved Hide resolved
Comment on lines 18 to 32
const sessionId = session ? session.id : 'no-session-id'
const queryParams: SessionReplayUrlQueryParams = {}

const errorType = getErrorType(session, isRecordingStarted)
if (errorType) {
queryParams.errorType = errorType
}

const view = viewContexts.findView()
if (view) {
queryParams.seed = view.id
queryParams.from = view.startClocks.timeStamp
}

return getSessionReplayUrl(configuration, sessionId, queryParams)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 suggestion: ‏what about passing directly session, view and errorType to getSessionReplayUrl?
it would avoid to declare query params outside of the link computation and would avoid to have no-session-id declared at several spots.

@ThibautGeriz ThibautGeriz requested a review from bcaudan April 6, 2023 16:48
ThibautGeriz and others added 3 commits April 7, 2023 10:16
Co-authored-by: Bastien Caudan <1331991+bcaudan@users.noreply.github.com>
Co-authored-by: Bastien Caudan <1331991+bcaudan@users.noreply.github.com>
Co-authored-by: Bastien Caudan <1331991+bcaudan@users.noreply.github.com>
@ThibautGeriz ThibautGeriz force-pushed the thibaut.gery/add-replay-link branch 3 times, most recently from 4375726 to 36d5195 Compare April 7, 2023 12:54
@ThibautGeriz ThibautGeriz force-pushed the thibaut.gery/add-replay-link branch from 36d5195 to 0333598 Compare April 7, 2023 13:51
@ThibautGeriz ThibautGeriz merged commit 5c77f3a into main Apr 11, 2023
@ThibautGeriz ThibautGeriz deleted the thibaut.gery/add-replay-link branch April 11, 2023 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants