-
Notifications
You must be signed in to change notification settings - Fork 142
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-1097] revamp internal configuration - core #1216
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { BuildEnv } from '../../boot/init' | ||
import { CookieOptions, getCurrentSite } from '../../browser/cookie' | ||
import { catchUserErrors } from '../../tools/catchUserErrors' | ||
import { objectHasValue, ONE_KILO_BYTE, ONE_SECOND } from '../../tools/utils' | ||
import { display } from '../../tools/display' | ||
import { isPercentage, objectHasValue, ONE_KILO_BYTE, ONE_SECOND } from '../../tools/utils' | ||
import { updateExperimentalFeatures } from './experimentalFeatures' | ||
import { computeTransportConfiguration, TransportConfiguration } from './transportConfiguration' | ||
|
||
export const DefaultPrivacyLevel = { | ||
|
@@ -95,12 +97,44 @@ export type Configuration = typeof DEFAULT_CONFIGURATION & | |
TransportConfiguration & { | ||
cookieOptions: CookieOptions | ||
|
||
service?: string | ||
beforeSend?: BeforeSendCallback | ||
service: string | undefined | ||
beforeSend: BeforeSendCallback | undefined | ||
|
||
actionNameAttribute?: string | ||
} | ||
|
||
export function validateAndBuildConfiguration( | ||
initConfiguration: InitConfiguration, | ||
buildEnv: BuildEnv | ||
): Configuration | undefined { | ||
if (!initConfiguration || !initConfiguration.clientToken) { | ||
display.error('Client Token is not configured, we will not send any data.') | ||
return | ||
} | ||
|
||
// Set the experimental feature flags as early as possible so we can use them in most places | ||
updateExperimentalFeatures(initConfiguration.enableExperimentalFeatures) | ||
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. I want to set experimental feature flags as early as possible. This is the earliest I can do, since we are checking if 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. sounds good to me |
||
|
||
const configuration: Configuration = { | ||
beforeSend: | ||
initConfiguration.beforeSend && catchUserErrors(initConfiguration.beforeSend, 'beforeSend threw an error:'), | ||
cookieOptions: buildCookieOptions(initConfiguration), | ||
service: initConfiguration.service, | ||
...computeTransportConfiguration(initConfiguration, buildEnv), | ||
...DEFAULT_CONFIGURATION, | ||
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. Following PRs will follow the same strategy to define default configuration, let me know what you think! 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. Should we trim the default configuration used here as well? 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. It is planned for later, when I move RUM-only options to the RUM package. |
||
} | ||
|
||
if (initConfiguration.sampleRate !== undefined) { | ||
if (!isPercentage(initConfiguration.sampleRate)) { | ||
display.error('Sample Rate should be a number between 0 and 100') | ||
return | ||
} | ||
configuration.sampleRate = initConfiguration.sampleRate | ||
} | ||
Comment on lines
+127
to
+133
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. Following PRs will follow the same strategy to validate and set the configuration, let me know what you think! 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. Sound good! 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. I want to collocate validation and definition, to avoid doing let sampleRate
if (initConfiguration.sampleRate !== undefined) {
if (!isPercentage(initConfiguration.sampleRate)) {
display.error('Sample Rate should be a number between 0 and 100')
return
}
sampleRate = initConfiguration.sampleRate
} else {
sampleRate = DEFAULT_SAMPLE_RATE
}
let configuration: Configuration = {
cookieOptions: buildCookieOptions(initConfiguration),
service: initConfiguration.service,
...computeTransportConfiguration(initConfiguration, buildEnv),
sampleRate,
} |
||
|
||
return configuration | ||
} | ||
|
||
export function buildConfiguration(initConfiguration: InitConfiguration, buildEnv: BuildEnv): Configuration { | ||
const configuration: Configuration = { | ||
beforeSend: | ||
|
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.
Using
service: string | undefined
instead ofservice?: string
to ensure that theservice
property is set ( slightly stricter typings).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.
Does it allow or prevent something compared to previous state?
Should we do the same for
actionNameAttribute
?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.
Yes, it ensures that the property is set. For example:
This will be changed in the RUM PR. This is a bit weird to change it now, since we don't want to set it in the core
validateAndBuildConfiguration
function.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.
OK, I think I get it, the idea is to be sure that for the internal configuration object, we set all the needed fields even if they are not set in the customer facing configuration.