-
Notifications
You must be signed in to change notification settings - Fork 127
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
98828 Add initial RUM implementation - form 10-10d #33772
base: main
Are you sure you want to change the base?
Changes from 4 commits
45ccbb2
e2d8fe2
9621320
0e3ea7b
14e9bcc
2d30289
34fa0a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adds RUM initialization function (modified from EZR form example). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useEffect, useMemo } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { datadogRum } from '@datadog/browser-rum'; | ||
|
||
import environment from '@department-of-veterans-affairs/platform-utilities/environment'; | ||
import { makeSelectFeatureToggles } from '../selectors/feature-toggles'; | ||
|
||
const initializeRealUserMonitoring = () => { | ||
// Prevent RUM from re-initializing the SDK OR running on local/CI environments. | ||
if ( | ||
!environment.BASE_URL.includes('localhost') && | ||
!window.DD_RUM?.getInitConfiguration() | ||
) { | ||
datadogRum.init({ | ||
applicationId: 'cca24a05-9ea0-49ea-aaa9-0d1e04a17ba0', | ||
clientToken: 'puba5e0866f8008f60a6bc8b09ae555dd92', | ||
site: 'ddog-gov.com', | ||
service: '10-10d', | ||
env: environment.vspEnvironment(), | ||
sessionSampleRate: 100, | ||
sessionReplaySampleRate: 100, | ||
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defaulting to 100% because we need to test in staging. Once we decide to start using in prod, this will have to change to a significantly reduced percentage. |
||
trackUserInteractions: true, | ||
trackFrustrations: true, | ||
trackResources: true, | ||
trackLongTasks: true, | ||
defaultPrivacyLevel: 'mask-user-input', | ||
}); | ||
|
||
// If sessionReplaySampleRate > 0, we need to manually start the recording | ||
datadogRum.startSessionReplayRecording(); | ||
} | ||
}; | ||
|
||
const useBrowserMonitoring = () => { | ||
// Retrieve feature flag values to control behavior | ||
const selectFeatureToggles = useMemo(makeSelectFeatureToggles, []); | ||
const featureToggles = useSelector(selectFeatureToggles); | ||
const { isBrowserMonitoringEnabled, isLoadingFeatureFlags } = featureToggles; | ||
|
||
useEffect( | ||
() => { | ||
if (isLoadingFeatureFlags) return; | ||
if (isBrowserMonitoringEnabled) { | ||
initializeRealUserMonitoring(); | ||
} else { | ||
delete window.DD_RUM; | ||
} | ||
}, | ||
[isBrowserMonitoringEnabled, isLoadingFeatureFlags], | ||
); | ||
}; | ||
|
||
export { useBrowserMonitoring }; | ||
Comment on lines
+34
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on existing RUM config examples in vets-website. Uses memoized feature toggle info when initializing RUM. |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Helper used later with |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createSelector } from 'reselect'; | ||
import { toggleValues } from '@department-of-veterans-affairs/platform-site-wide/selectors'; | ||
import FEATURE_FLAG_NAMES from '@department-of-veterans-affairs/platform-utilities/featureFlagNames'; | ||
|
||
const selectFeatureToggles = createSelector( | ||
state => ({ | ||
isLoadingFeatureFlags: state?.featureToggles?.loading, | ||
isBrowserMonitoringEnabled: toggleValues(state)[ | ||
FEATURE_FLAG_NAMES.form1010dBrowserMonitoringEnabled | ||
], | ||
}), | ||
toggles => toggles, | ||
); | ||
|
||
const makeSelectFeatureToggles = () => selectFeatureToggles; | ||
|
||
export { makeSelectFeatureToggles }; | ||
Comment on lines
+1
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on existing RUM config examples in vets-website. Creates a redux selector so these extra bits of state can be derived rather than directly stored. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { expect } from 'chai'; | ||
import { makeSelectFeatureToggles } from '../../../selectors/feature-toggles'; | ||
|
||
describe('10-10d RUM FeatureToggles selector', () => { | ||
const state = { | ||
featureToggles: { | ||
/* eslint-disable camelcase */ | ||
michaelclement marked this conversation as resolved.
Show resolved
Hide resolved
|
||
form1010d_browser_monitoring_enabled: true, | ||
loading: false, | ||
}, | ||
}; | ||
|
||
describe('when `makeSelectFeatureToggles` executes', () => { | ||
it('should return feature toggles', () => { | ||
const selectFeatureToggles = makeSelectFeatureToggles(); | ||
expect(selectFeatureToggles(state)).to.eql({ | ||
isLoadingFeatureFlags: false, | ||
isBrowserMonitoringEnabled: true, | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reordered, nothing important here.