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

Log exceptions and request-reply as JSON #437

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
this.metrics.writeCommand(interaction, latency);
} catch (error) {
this.metrics.writeCommand(interaction, -1);
this.logger.error(serialiseInteraction(interaction), error);
this.logger.error(serialiseInteraction(interaction, { error, stack: (error as Error).stack }), error);

Check warning on line 46 in src/Command.ts

View check run for this annotation

Codecov / codecov/patch

src/Command.ts#L46

Added line #L46 was not covered by tests
let method;
if (interaction.replied) {
method = "followUp" as const;
Expand Down
36 changes: 20 additions & 16 deletions src/got.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,29 @@ export default function createGotClient(): Got {
hooks: {
beforeRequest: [
options =>
logger.info({
event: "beforeRequest",
method: options.method,
url: options.url.toString(),
timeout: options.timeout,
headers: options.headers
})
logger.info(
JSON.stringify({
event: "beforeRequest",
method: options.method,
url: options.url,
timeout: options.timeout,
headers: options.headers
})
)
],
afterResponse: [
response => (
logger.info({
event: "afterResponse",
method: response.request.options.method,
url: response.requestUrl,
code: response.statusCode,
timings: response.timings,
headers: response.rawHeaders,
body: response.body
}),
logger.info(
JSON.stringify({
event: "afterResponse",
method: response.request.options.method,
url: response.requestUrl,
code: response.statusCode,
timings: response.timings,
headers: response.rawHeaders,
body: response.body
})
),
response
)
]
Expand Down