-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
fix: serialize request.data in logging middleware #47778
Conversation
Reviewer Checklist
Screenshots/VideosAndroid: NativeScreen.Recording.2024-08-28.at.23.49.37.mp4Android: mWeb ChromeScreen.Recording.2024-08-28.at.23.26.25.mp4iOS: NativeScreen.Recording.2024-08-28.at.23.39.03.mp4iOS: mWeb SafariScreen.Recording.2024-08-28.at.23.39.03.mp4MacOS: Chrome / SafariScreen.Recording.2024-08-29.at.00.39.05.mp4Screen.Recording.2024-08-28.at.23.19.55.mp4MacOS: DesktopScreen.Recording.2024-08-28.at.23.23.11.mp4 |
src/libs/Middleware/Logging.ts
Outdated
| (Record<string, never> | Set<Serializable>) | ||
| (Record<string, never> | Serializable[]); | ||
|
||
function serializeValue(data: unknown) { |
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.
For logging, we store primitive data types, so we can simplify the logic of this function by using JSON.stringify
with a replacer function can reduce to create a test for current change so we can just implement
JSON.parse(JSON.stringify(data, getCircularReplacer()))
Function getCircularReplacer
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.
Noted. Working on this now.
src/libs/Middleware/Logging.ts
Outdated
extraData.request = request; | ||
extraData.request = { | ||
...request, | ||
data: JSON.parse(JSON.stringify(request.data, getCircularReplacer())) as Record<string, unknown>, |
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.
NAB: Nice to have, we can move this logic into the function serializeLoggingValue
.
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.
LGTM, using JSON functionality can simplify the logic.
Can you expand on what you mean by this? And if it would make the logic simpler, should we do it? |
@puneetlath By using the JSON stringify/parse approach, we simplify the process of serializing complex objects and avoid custom recursive logic, rather than creating a new recursive function and manually handling various data types.
I think we should leverage the existing functions to make the code cleaner and more maintainable. |
Ok let's do that then. What do you think @dominictb? |
@puneetlath @suneox updated. |
Great. @suneox can you please re-review? |
src/libs/Middleware/Logging.ts
Outdated
}; | ||
} | ||
|
||
function serializeLoggingData(logData?: Record<string, unknown> | null): Record<string, unknown> | undefined | null { |
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.
Nice to have support to keep the data type of object after serialization
function serializeLoggingData(logData?: Record<string, unknown> | null): Record<string, unknown> | undefined | null { | |
function serializeLoggingData<T extends Record<string, unknown>>(logData: T): T | null { | |
try { | |
return JSON.parse(JSON.stringify(logData, getCircularReplacer())) as T; | |
} catch (error) { | |
Log.hmmm('Failed to serialize log data', {error}); | |
return null; | |
} | |
} |
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.
Hi @dominictb i've updated suggestion
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.
Are we going to implement this suggestion?
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.
@dominictb have you got any feedback on this suggestion?
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.
Looking into this now
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.
@suneox if we fail to serialize the data, shall we return dummy value like [Not serializable]
or something? If we return the original data I'm afraid we could get into the original freeze
issue again.
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 got it, so if fail to serialize data we can return null instead of original data
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.
Cool, I'll update and let you know.
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.
Done!
@dominictb Could you please update my suggested changes? It includes handling error. Once that’s done, I’ll approve it again. Thank you |
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.
LGTM
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by https://github.com/puneetlath in version: 9.0.30-0 🚀
|
Details
Fixed Issues
$ #47509
PROPOSAL: #47509 (comment)
Tests
Verify that there're no infinite errors occur in the console, the file is sent and the app function normally
Offline tests
QA Steps
Verify that there're no infinite errors occur in the console, the file is sent and the app function normally
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
compressed_android.webm.mp4
Android: mWeb Chrome
compressed_aweb.webm.mp4
iOS: Native
compressed_ios.mp4.mp4
iOS: mWeb Safari
compressed_iosweb.mp4.mp4
MacOS: Chrome / Safari
MacOS: Desktop
compressed_web.mov.mp4