Skip to content

Conversation

@rowanmanning
Copy link
Member

@rowanmanning rowanmanning commented Apr 4, 2023

This resolves #489. We were not matching n-logger in the way it serialized functions and this resulted in errors. We now match n-logger and just ignore any function properties.

I did this using the lossy option of ungap's structured-clone, which offers a few features over the native structured clone. The lossy option makes the clone behave more like JSON.stringify, ignoring properties that it can't serialize rather than throwing an error. Once Reliability Kit drops Node.js 16 support we can reassess this and perhaps move to native structuredClone.

@rowanmanning rowanmanning requested a review from a team as a code owner April 4, 2023 09:16
const pino = require('pino').default;
const serializeError = require('@dotcom-reliability-kit/serialize-error');
const { default: structuredClone } = require('@ungap/structured-clone');
const { default: clone } = require('@ungap/structured-clone');
Copy link
Member Author

Choose a reason for hiding this comment

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

note: I renamed this to avoid confusion. In Node.js 18+ structuredClone is a global which doesn't exactly match the method signature of ungap's structured-clone module. I can imagine this confusing us a lot later.

@rowanmanning rowanmanning force-pushed the fix-function-serialization branch from e42def5 to f80fb13 Compare April 4, 2023 09:24
This resolves #489. We were not matching n-logger in the way it
serialized functions and this resulted in errors. We now match n-logger
and just ignore any function properties.

I did this using the `lossy` option of ungap's structured-clone, which
offers a few features over the native structured clone. Once Reliability
Kit drops Node.js 16 support we can reassess this and perhaps move to
native `structuredClone`.

Docs are here: https://github.com/ungap/structured-clone#extra-features
@rowanmanning rowanmanning force-pushed the fix-function-serialization branch from f80fb13 to 10d86f2 Compare April 4, 2023 09:24
@rowanmanning rowanmanning changed the title Fix function serialization fix: match n-logger's function serialization Apr 4, 2023
Copy link
Member

@alexmuller alexmuller 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! 👍

@rowanmanning rowanmanning merged commit 9997836 into main Apr 4, 2023
@rowanmanning rowanmanning deleted the fix-function-serialization branch April 4, 2023 15:45
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.

The logger does not serialize functions in the same way as n-logger

3 participants