-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: Omit specific headers by default #92
Merged
Merged
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0c7e42a
feat: Add omitProperties
ConradLang d852b69
feat: Add omitPropertiesSerializer
ConradLang 51bdeeb
feat: Omit default headers from headers property
ConradLang 8502fe6
feat: Omit default headers from req.headers prop
ConradLang cea3d28
refactor: Remove default export from serializers
ConradLang 13e30c0
chore: Create changeset
ConradLang 8f3f4b2
Change to minor release
ConradLang 20632fe
Remove export
72636c b657f4b
Simplify `omitProperties`
72636c ad3e48d
Avoid making an assumption about the record shape
72636c 22fa653
Simplify `createOmitPropertiesSerializer`
72636c b7f29b1
Restore test case
72636c eedcb17
Reduce type assertions
72636c 69be74e
Tweak a reduce
72636c fb39c6c
Remove an export
72636c b579ec0
Hoist spreading to index
72636c 0026477
Test serializer merging
72636c a41ceca
Lock in interface
72636c File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
'@seek/logger': minor | ||
--- | ||
|
||
Omit a default set or the specified headers from the logged object | ||
|
||
By default, the following headers in the `headers` and `req.headers` | ||
properties will be omitted from the logged object: | ||
|
||
- 'x-envoy-attempt-count' | ||
- 'x-envoy-decorator-operation' | ||
- 'x-envoy-expected-rq-timeout-ms' | ||
- 'x-envoy-external-address' | ||
- 'x-envoy-internal' | ||
- 'x-envoy-peer-metadata' | ||
- 'x-envoy-peer-metadata-id' | ||
- 'x-envoy-upstream-service-time' | ||
|
||
If you would like to opt out of this, you can provide an empty list or your | ||
own list of headers to omit in the `omitHeaderNames` property when creating | ||
your logger e.g. | ||
|
||
```typescript | ||
const logger = createLogger({ | ||
name: 'my-app', | ||
omitHeaderNames: ['dnt', 'sec-fetch-dest'], | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { omitProperties } from './omitProperties'; | ||
|
||
const omitPropertyNames = ['omit-prop', 'omit.prop', '', '0']; | ||
|
||
const createInput = (): Readonly<Record<string, unknown>> => | ||
Object.freeze({ | ||
keepProp: 'Some value', | ||
['omit-prop']: 'omit with dash', | ||
['omit.prop']: 'omit with dot', | ||
['']: 'omit with empty key', | ||
['0']: 'omit number as text key', | ||
omit: { prop: 'DO NOT omit' }, | ||
}); | ||
|
||
it('omits list of keys from object', () => { | ||
const input = createInput(); | ||
|
||
const result = omitProperties(input, omitPropertyNames); | ||
|
||
expect(result).toStrictEqual({ | ||
keepProp: 'Some value', | ||
omit: { prop: 'DO NOT omit' }, | ||
}); | ||
}); | ||
|
||
it('does not alter input object', () => { | ||
const input = createInput(); | ||
|
||
const originalInput = structuredClone(input); | ||
|
||
omitProperties(input, omitPropertyNames); | ||
|
||
expect(input).toEqual(originalInput); | ||
}); | ||
|
||
it.each` | ||
scenario | input | ||
${'undefined'} | ${undefined} | ||
${'null'} | ${null} | ||
${'an empty object'} | ${{}} | ||
${'not an object'} | ${'key1=value1,key2=value2'} | ||
${'an array'} | ${[{ key1: 'value1' }, { key2: 'value2' }]} | ||
`('returns input when it is $scenario', ({ input }) => { | ||
const result = omitProperties(input, omitPropertyNames); | ||
|
||
expect(result).toStrictEqual(input); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is the release summary format ok?
I'm not sure what it will look like in the release notes.