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

Add truncation to all serializers #143

Merged
merged 8 commits into from
Jul 28, 2024
Merged

Add truncation to all serializers #143

merged 8 commits into from
Jul 28, 2024

Conversation

zbrydon
Copy link
Contributor

@zbrydon zbrydon commented Jul 17, 2024

Purpose

Adds changes and refactors based on suggestions from #141

Approach

  • Adds trimming to all serializers
  • Reuses shared trimmer between serializers
  • Excludes stack field from trimming in err and errWithCause serializers
  • Defines the default maxObjectDepth once
  • Condensed some related/duplicate tests

@zbrydon zbrydon requested a review from a team July 17, 2024 04:44
Copy link

changeset-bot bot commented Jul 17, 2024

🦋 Changeset detected

Latest commit: 5cae60c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@seek/logger Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -1 +1,2 @@
export type SerializerFn = (input: unknown) => unknown;
export type TrimmerFn = (input: unknown) => unknown;
export type SerializerFn<T> = (input: T) => unknown;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not convinced with this one because of the different placed I had to change 😬

@@ -1,6 +1,8 @@
import { trimmer } from 'dtrim';
import type { LoggerOptions } from 'pino';

export const DEFAULT_MAX_OBJECT_DEPTH = 4;
Copy link
Contributor Author

@zbrydon zbrydon Jul 17, 2024

Choose a reason for hiding this comment

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

Looking for suggestions on this default value, given this potential usecase.

Copy link
Member

@72636c 72636c left a comment

Choose a reason for hiding this comment

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

🙇

.changeset/smooth-ties-look.md Outdated Show resolved Hide resolved
src/serializers/index.ts Outdated Show resolved Hide resolved
Comment on lines -444 to -447
headers: {
Accept: 'application/json, text/plain, */*',
authorization: '[Redacted]',
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now truncated as a result of fixing the max object depth.

Copy link
Member

Choose a reason for hiding this comment

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

Random stream of consciousness thought, do we know if the trimming impacts a potentially deep err.stack trace? Perhaps we could pull some (non-sensitive) ones out of Splunk and have a test case around it? The stack trace tends to be the highest value field in an error log, so retaining a long stack may be a safer default.

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 excluded the stack field from being trimmed, though the sharing of a trimmer between serializers means that its not just the top level fields of err and errWithCause that are affected by this exclusion.

Copy link
Member

Choose a reason for hiding this comment

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

I was poking around with this, do you have thoughts on 7b1f2a1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure do that's way cleaner I like it!!
Cleaned up and condensed all the bits of spread out logic that I implemented and didn't like 😆 🙏

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the change, refactoring is the easy part 😉

src/index.ts Outdated
Comment on lines 41 to 44
const trim = trimmer({
depth: (opts.maxObjectDepth ?? DEFAULT_MAX_OBJECT_DEPTH) - 1,
});

Copy link
Contributor Author

@zbrydon zbrydon Jul 23, 2024

Choose a reason for hiding this comment

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

Am torn between sharing a trimmer like this or just re-declaring for both default and custom serializers. 🤔

src/serializers/index.ts Outdated Show resolved Hide resolved
Copy link
Member

@72636c 72636c left a comment

Choose a reason for hiding this comment

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

Looks good to go once we're happy with the changeset 😃

Comment on lines -444 to -447
headers: {
Accept: 'application/json, text/plain, */*',
authorization: '[Redacted]',
},
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the change, refactoring is the easy part 😉

@zbrydon zbrydon merged commit de78e36 into master Jul 28, 2024
4 checks passed
@zbrydon zbrydon deleted the trim-all-serializers branch July 28, 2024 23:17
@seek-oss-ci seek-oss-ci mentioned this pull request Jul 28, 2024
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