Skip to content

Commit 5ee006f

Browse files
committed
fix: enhance logging for request node
1 parent 78a353d commit 5ee006f

File tree

5 files changed

+53
-8
lines changed

5 files changed

+53
-8
lines changed

packages/request-node/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"graphql-request": "6.1.0",
5959
"http-shutdown": "1.2.2",
6060
"http-status-codes": "2.1.4",
61+
"morgan": "^1.10.0",
6162
"shelljs": "0.8.5",
6263
"tslib": "2.5.0",
6364
"yargs": "17.6.2"
@@ -66,6 +67,7 @@
6667
"@types/cors": "2.8.9",
6768
"@types/express": "4.17.17",
6869
"@types/jest": "29.5.6",
70+
"@types/morgan": "^1.9.9",
6971
"@types/node": "18.11.9",
7072
"@types/supertest": "2.0.10",
7173
"@types/yargs": "17.0.14",

packages/request-node/src/request/ipfsAdd.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ export default class IpfsAddHandler {
2626

2727
// Set the timeout from the value from config and convert seconds to milliseconds
2828
/* eslint-disable no-magic-numbers */
29-
clientRequest.setTimeout(getPersistTransactionTimeout() * 1000);
29+
clientRequest.setTimeout(getPersistTransactionTimeout() * 1000, () => {
30+
this.logger.error('ipfs add timeout');
31+
serverResponse.status(StatusCodes.GATEWAY_TIMEOUT).send('ipfs add timeout');
32+
});
3033

3134
// Verifies if data send from post are correct
3235
// clientRequest.body is expected to contain data for data-acces layer:
@@ -48,12 +51,23 @@ export default class IpfsAddHandler {
4851
JSON.stringify(clientRequest.body.data),
4952
);
5053

51-
this.logger.debug(`ipfsAdd successfully completed`, ['metric', 'successRate']);
54+
this.logger.debug(
55+
`ipfsAdd successfully completed ${JSON.stringify({
56+
ipfsHash: dataAccessResponse.ipfsHash,
57+
ipfsSize: dataAccessResponse.ipfsSize,
58+
})}`,
59+
['metric', 'successRate'],
60+
);
5261

5362
serverResponse.status(StatusCodes.OK).send(dataAccessResponse);
5463
} catch (e) {
5564
this.logger.error(`ipfsAdd error: ${e}`);
56-
this.logger.debug(`ipfsAdd fail`, ['metric', 'successRate']);
65+
this.logger.debug(
66+
`ipfsAdd fail ${JSON.stringify({
67+
data: clientRequest.body.data,
68+
})}`,
69+
['metric', 'successRate'],
70+
);
5771

5872
serverResponse.status(StatusCodes.INTERNAL_SERVER_ERROR).send(e);
5973
}

packages/request-node/src/request/persistTransaction.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ export default class PersistTransactionHandler {
3232

3333
// Set the timeout from the value from config and convert seconds to milliseconds
3434
/* eslint-disable no-magic-numbers */
35-
clientRequest.setTimeout(getPersistTransactionTimeout() * 1000);
35+
clientRequest.setTimeout(getPersistTransactionTimeout() * 1000, () => {
36+
this.logger.error('persistTransaction timeout');
37+
serverResponse.status(StatusCodes.GATEWAY_TIMEOUT).send('persistTransaction timeout');
38+
});
3639

3740
// Verifies if data send from post are correct
3841
// clientRequest.body is expected to contain data for data-acces layer:
@@ -83,12 +86,27 @@ export default class PersistTransactionHandler {
8386
)}`);
8487
});
8588

86-
this.logger.debug(`persistTransaction successfully completed`, ['metric', 'successRate']);
89+
this.logger.debug(
90+
`persistTransaction successfully completed ${JSON.stringify({
91+
transactionHash,
92+
channelId: clientRequest.body.channelId,
93+
topics: clientRequest.body.topics,
94+
transactionData: clientRequest.body.transactionData,
95+
})}`,
96+
['metric', 'successRate'],
97+
);
8798

8899
serverResponse.status(StatusCodes.OK).send(dataAccessResponse);
89100
} catch (e) {
90101
this.logger.error(`persistTransaction error: ${e}`);
91-
this.logger.debug(`persistTransaction fail`, ['metric', 'successRate']);
102+
this.logger.debug(
103+
`persistTransaction fail ${JSON.stringify({
104+
channelId: clientRequest.body.channelId,
105+
topics: clientRequest.body.topics,
106+
transactionData: clientRequest.body.transactionData,
107+
})}`,
108+
['metric', 'successRate'],
109+
);
92110

93111
serverResponse.status(StatusCodes.INTERNAL_SERVER_ERROR).send(e);
94112
}

packages/request-node/src/requestNode.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import PersistTransactionHandler from './request/persistTransaction';
1111
import GetChannelsByTopicHandler from './request/getChannelsByTopic';
1212
import GetStatusHandler from './request/getStatus';
1313
import IpfsAddHandler from './request/ipfsAdd';
14+
import morgan from 'morgan';
1415

1516
// eslint-disable-next-line @typescript-eslint/no-var-requires
1617
const packageJson = require('../package.json');
@@ -133,6 +134,9 @@ export class RequestNode {
133134
// Enable all CORS requests
134135
this.express.use(cors());
135136

137+
// Enable logging of all requests
138+
this.express.use(morgan('combined'));
139+
136140
// Set the Request Node version to the header
137141
this.express.use((_, res, next) => {
138142
res.header(REQUEST_NODE_VERSION_HEADER, this.requestNodeVersion);

yarn.lock

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5319,6 +5319,13 @@
53195319
resolved "https://registry.npmjs.org/@types/mocha/-/mocha-8.2.3.tgz"
53205320
integrity sha512-ekGvFhFgrc2zYQoX4JeZPmVzZxw6Dtllga7iGHzfbYIYkAMUx/sAFP2GdFpLff+vdHXu5fl7WX9AT+TtqYcsyw==
53215321

5322+
"@types/morgan@^1.9.9":
5323+
version "1.9.9"
5324+
resolved "https://registry.yarnpkg.com/@types/morgan/-/morgan-1.9.9.tgz#d60dec3979e16c203a000159daa07d3fb7270d7f"
5325+
integrity sha512-iRYSDKVaC6FkGSpEVVIvrRGw0DfJMiQzIn3qr2G5B3C//AWkulhXgaBd7tS9/J79GWSYMTHGs7PfI5b3Y8m+RQ==
5326+
dependencies:
5327+
"@types/node" "*"
5328+
53225329
"@types/multicoin-address-validator@0.5.0":
53235330
version "0.5.0"
53245331
resolved "https://registry.npmjs.org/@types/multicoin-address-validator/-/multicoin-address-validator-0.5.0.tgz"
@@ -16876,9 +16883,9 @@ module-error@^1.0.1, module-error@^1.0.2:
1687616883
resolved "https://registry.npmjs.org/module-error/-/module-error-1.0.2.tgz"
1687716884
integrity sha512-0yuvsqSCv8LbaOKhnsQ/T5JhyFlCYLPXK3U2sgV10zoKQwzs/MyfuQUOZQ1V/6OCOJsK/TRgNVrPuPDqtdMFtA==
1687816885

16879-
morgan@^1.9.1:
16886+
morgan@^1.10.0, morgan@^1.9.1:
1688016887
version "1.10.0"
16881-
resolved "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz"
16888+
resolved "https://registry.yarnpkg.com/morgan/-/morgan-1.10.0.tgz#091778abc1fc47cd3509824653dae1faab6b17d7"
1688216889
integrity sha512-AbegBVI4sh6El+1gNwvD5YIck7nSA36weD7xvIxG4in80j/UoK8AEGaWnnz8v1GxonMCltmlNs5ZKbGvl9b1XQ==
1688316890
dependencies:
1688416891
basic-auth "~2.0.1"

0 commit comments

Comments
 (0)