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

♻ [RUMF-1097] revamp internal configuration - core #1216

Merged
merged 3 commits into from
Dec 14, 2021

Conversation

BenoitZugmeyer
Copy link
Member

@BenoitZugmeyer BenoitZugmeyer commented Dec 13, 2021

Motivation

We want to revamp the internal configuration object to improve the separation between RUM and Logs SDKs and get more precise typings.

Changes

As a first step to revamp the internal configuration objects, this PR introduce a validateAndBuildConfiguration which, in the following PRs, will replace buildConfiguration usages.

It also removes the commonInit function by inlining it into the two SDKs, so the code can be customized in each codebases.

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@BenoitZugmeyer BenoitZugmeyer requested a review from a team as a code owner December 13, 2021 15:51
cookieOptions: buildCookieOptions(initConfiguration),
service: initConfiguration.service,
...computeTransportConfiguration(initConfiguration, buildEnv),
...DEFAULT_CONFIGURATION,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we trim the default configuration used here as well?
or is it planned for later?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

@@ -95,12 +97,44 @@ export type Configuration = typeof DEFAULT_CONFIGURATION &
TransportConfiguration & {
cookieOptions: CookieOptions

service?: string
beforeSend?: BeforeSendCallback
service: string | undefined
Copy link
Member Author

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 of service?: string to ensure that the service property is set ( slightly stricter typings).

Copy link
Contributor

@bcaudan bcaudan Dec 14, 2021

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Does it change something?

Yes, it ensures that the property is set. For example:

type Configuration = { foo?: string }

let configuration: Configuration = {} // no error. We may have forgot to set `foo` from `initConfiguration`


type Configuration = { foo: string | undefined }

let configuration: Configuration = {} // error
let configuration: Configuration = { foo: initConfiguration.foo } // ok

Should we do the same for actionNameAttribute?

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.

Copy link
Contributor

@bcaudan bcaudan Dec 14, 2021

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.

cookieOptions: buildCookieOptions(initConfiguration),
service: initConfiguration.service,
...computeTransportConfiguration(initConfiguration, buildEnv),
...DEFAULT_CONFIGURATION,
Copy link
Member Author

Choose a reason for hiding this comment

The 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!

Comment on lines +127 to +133
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
}
Copy link
Member Author

Choose a reason for hiding this comment

The 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!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sound good!
Maybe we could move the validation, next to the clientToken validation.

Copy link
Member Author

Choose a reason for hiding this comment

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

I want to collocate validation and definition, to avoid doing initConfiguration.sampleRate !== undefined twice. I tried to move this block above, but this prevent to use DEFAULT_CONFIGURATION as we do currently, resulting on something a bit more verbose:

  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,
  }

}

// Set the experimental feature flags as early as possible so we can use them in most places
updateExperimentalFeatures(initConfiguration.enableExperimentalFeatures)
Copy link
Member Author

Choose a reason for hiding this comment

The 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 initConfiguration isn't falsy just above. This deviates a bit from the purpose of the function though, let me know what you think.

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good to me

@codecov-commenter
Copy link

Codecov Report

Merging #1216 (e86a9ef) into main (cbfe637) will decrease coverage by 0.01%.
The diff coverage is 94.73%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1216      +/-   ##
==========================================
- Coverage   89.08%   89.06%   -0.02%     
==========================================
  Files         100      100              
  Lines        4305     4317      +12     
  Branches      981      985       +4     
==========================================
+ Hits         3835     3845      +10     
- Misses        470      472       +2     
Impacted Files Coverage Δ
packages/core/src/boot/init.ts 88.88% <ø> (-2.42%) ⬇️
...ges/core/src/domain/configuration/configuration.ts 95.23% <92.30%> (-1.32%) ⬇️
packages/logs/src/boot/startLogs.ts 93.61% <100.00%> (+0.28%) ⬆️
packages/rum-core/src/boot/rumPublicApi.ts 93.80% <100.00%> (+0.11%) ⬆️
packages/core/src/tools/timeUtils.ts 97.14% <0.00%> (-2.86%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cbfe637...e86a9ef. Read the comment docs.

@BenoitZugmeyer BenoitZugmeyer merged commit 3f0ab47 into main Dec 14, 2021
@BenoitZugmeyer BenoitZugmeyer deleted the benoit/revamp-configuration-core branch December 14, 2021 15:54
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