Skip to content

Commit

Permalink
chore(middleware-logger): emit $metadata from output
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Dec 23, 2020
1 parent a94d181 commit 8265db4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 31 deletions.
22 changes: 2 additions & 20 deletions packages/middleware-logger/src/loggerMiddleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,7 @@ describe("loggerMiddleware", () => {
commandName,
input: mockInputLog,
output: mockOutputLog,
metadata: {
statusCode: mockResponse.response.statusCode,
requestId: mockResponse.response.headers["x-amzn-requestid"],
extendedRequestId: mockResponse.response.headers["x-amz-id-2"],
cfId: mockResponse.response.headers["x-amz-cf-id"],
retry: {
attempts: $metadata.attempts,
totalDelay: $metadata.totalRetryDelay,
},
},
metadata: $metadata,
});
});

Expand Down Expand Up @@ -154,16 +145,7 @@ describe("loggerMiddleware", () => {
expect(logger.info).toHaveBeenCalledWith({
input: mockArgs.input,
output: outputWithoutMetadata,
metadata: {
statusCode: customResponse.response.statusCode,
requestId: requestIdBackup,
extendedRequestId: undefined,
cfId: undefined,
retry: {
attempts: $metadata.attempts,
totalDelay: $metadata.totalRetryDelay,
},
},
metadata: $metadata,
});
});
});
Expand Down
12 changes: 1 addition & 11 deletions packages/middleware-logger/src/loggerMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,13 @@ export const loggerMiddleware = () => <Output extends MetadataBearer = MetadataB
}

if (typeof logger.info === "function") {
const httpResponse = response.response as HttpResponse;
const { $metadata, ...outputWithoutMetadata } = response.output;
logger.info({
clientName,
commandName,
input: inputFilterSensitiveLog(args.input),
output: outputFilterSensitiveLog(outputWithoutMetadata),
metadata: {
statusCode: httpResponse.statusCode,
requestId: httpResponse.headers["x-amzn-requestid"] ?? httpResponse.headers["x-amzn-request-id"],
extendedRequestId: httpResponse.headers["x-amz-id-2"],
cfId: httpResponse.headers["x-amz-cf-id"],
retry: {
attempts: $metadata.attempts,
totalDelay: $metadata.totalRetryDelay,
},
},
metadata: $metadata,
});
}

Expand Down

0 comments on commit 8265db4

Please sign in to comment.