Skip to content

Commit

Permalink
fix(source-aws): prevent s3 client from being logged when errors are …
Browse files Browse the repository at this point in the history
…thrown (#1475)

### Motivation

The `source` object is thrown when errors happen such as when a read
fails. If this error is logged then the `soruce.client` is also logged
and logging the entire S3 client is huge.

### Modification

Prevent the S3 object from being visible for loggers
  • Loading branch information
blacha authored Aug 22, 2024
1 parent a5c0e96 commit d146aa1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/source-aws/src/__test__/source.aws.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ describe('SourceAwsS3', () => {
it('should create s3 links from string url', () => {
assert.equal(new SourceAwsS3('s3://foo/bar.txt').url.href, 's3://foo/bar.txt');
});

it('should not expose "client" for logging', () => {
const source = new SourceAwsS3('s3://foo/bar.txt');
const keys = Object.keys(source);
assert.equal(keys.includes('client'), false);
assert.notEqual(source.client.config, null);
});
});
2 changes: 2 additions & 0 deletions packages/source-aws/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export class SourceAwsS3 implements Source {

constructor(url: URL | string, client: S3Client = new S3Client({})) {
this.url = typeof url === 'string' ? new URL(url) : url;
// S3 clients are very large and if this object gets logged the log is very very large
Object.defineProperty(this, 'client', { enumerable: false });
this.client = client;
}

Expand Down

0 comments on commit d146aa1

Please sign in to comment.