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

♻️ Remove automatic snake case #699

Merged
merged 5 commits into from
Jan 25, 2021
Merged

♻️ Remove automatic snake case #699

merged 5 commits into from
Jan 25, 2021

Conversation

bcaudan
Copy link
Contributor

@bcaudan bcaudan commented Jan 22, 2021

Motivation

Our properties need to be snake cased but not customer properties.
Automatic conversion + exception for customer properties can be error prone if we forget to add exception when we add new customer properties.

Changes

  • Declare snake cased properties in RawRumEvents
  • Remove automatic snake case logic

Testing

Unit


I have gone over the contributing documentation.

@bcaudan bcaudan requested a review from a team as a code owner January 22, 2021 14:07
Copy link
Member

@BenoitZugmeyer BenoitZugmeyer left a comment

Choose a reason for hiding this comment

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

Looks great!

packages/rum-core/src/domain/internalContext.ts Outdated Show resolved Hide resolved
count: action.counts.longTaskCount,
},
resource: {
count: action.counts.resourceCount,
},
},
}
} as Partial<RawRumActionEvent>)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this cast?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added it because ts was not complaining with the old format.
It compiles without it but then autoActionProperties could be anything.
wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

FMU, the issue was because loadingTime and longTask are optional properties. What about using an approach similar to https://medium.com/terria/typescript-transforming-optional-properties-to-required-properties-that-may-be-undefined-7482cb4e1585 ? I guess it could be useful at other places too.

diff --git packages/rum-core/src/domain/rumEventsCollection/action/actionCollection.ts packages/rum-core/src/domain/rumEventsCollection/action/actionCollection.ts
index 201f0f9f..08a712f7 100644
--- packages/rum-core/src/domain/rumEventsCollection/action/actionCollection.ts
+++ packages/rum-core/src/domain/rumEventsCollection/action/actionCollection.ts
@@ -22,10 +22,13 @@ export function startActionCollection(lifeCycle: LifeCycle, configuration: Confi
   }
 }

+type Complete<T> = {
+  [P in keyof Required<T>]: Pick<T, P> extends Required<Pick<T, P>> ? Complete<T[P]> : Complete<T[P]> | undefined
+}
+
 function processAction(action: AutoAction | CustomAction) {
   const autoActionProperties = isAutoAction(action)
-    ? // tslint:disable-next-line: no-object-literal-type-assertion
-      ({
+    ? {
         action: {
           error: {
             count: action.counts.errorCount,
@@ -39,10 +42,10 @@ function processAction(action: AutoAction | CustomAction) {
             count: action.counts.resourceCount,
           },
         },
-      } as Partial<RawRumActionEvent>)
+      }
     : undefined
   const customerContext = !isAutoAction(action) ? action.context : undefined
-  const actionEvent: RawRumActionEvent = combine(
+  const actionEvent: Complete<RawRumActionEvent> = combine(
     {
       action: {
         target: {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that the issue is related to optional properties, for ex with:

action: {
  foo: 'bar',
  error: {
    count: action.counts.errorCount,
  },
  ...
}

I would expect a ts issue since foo is not defined on RawRumActionEvent but it is not the case.

Anyway, since the automatic snake case has been removed, this error is as least caught by unit tests.
I've removed the explicit casting.

@codecov-io
Copy link

Codecov Report

Merging #699 (8e8d42f) into master (052c30e) will increase coverage by 0.02%.
The diff coverage is 93.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #699      +/-   ##
==========================================
+ Coverage   79.58%   79.60%   +0.02%     
==========================================
  Files          68       68              
  Lines        3448     3433      -15     
  Branches      737      737              
==========================================
- Hits         2744     2733      -11     
+ Misses        704      700       -4     
Impacted Files Coverage Δ
packages/core/src/tools/context.ts 85.10% <ø> (-3.42%) ⬇️
packages/rum-core/src/domain/lifeCycle.ts 100.00% <ø> (ø)
...rumEventsCollection/longTask/longTaskCollection.ts 100.00% <ø> (ø)
...main/rumEventsCollection/resource/resourceUtils.ts 96.42% <ø> (ø)
packages/rum-core/src/rawRumEvent.types.ts 100.00% <ø> (ø)
packages/rum-core/test/fixtures.ts 100.00% <ø> (ø)
packages/rum-core/src/domain/internalContext.ts 88.88% <75.00%> (-11.12%) ⬇️
packages/rum-core/src/domain/assembly.ts 100.00% <100.00%> (ø)
...ain/rumEventsCollection/action/actionCollection.ts 94.11% <100.00%> (ø)
...omain/rumEventsCollection/error/errorCollection.ts 100.00% <100.00%> (ø)
... and 5 more

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 052c30e...8e8d42f. Read the comment docs.

@bcaudan bcaudan merged commit e2d7bae into master Jan 25, 2021
@bcaudan bcaudan deleted the bcaudan/snake-case branch January 25, 2021 09:57
kcaffrey pushed a commit to WonderInventions/browser-sdk that referenced this pull request Jan 29, 2021
* ♻️ replace camelCase by snake_case for RawRumEvents

* 🔥 remove snake case conversion

* 👌 do not remap view properties

Co-authored-by: Benoît <[email protected]>

* 👌 remove cast

Co-authored-by: Benoît <[email protected]>
kcaffrey added a commit to WonderInventions/browser-sdk that referenced this pull request Jan 29, 2021
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.

3 participants