Skip to content

Commit a2d40c9

Browse files
author
Jeel Mehta
committed
Merge branch 'main' into Node_SigV4_logs_release_testing
2 parents 97ce687 + 6c7b924 commit a2d40c9

File tree

6 files changed

+61
-32
lines changed

6 files changed

+61
-32
lines changed

sample-apps/node/frontend-service/index.js

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
const http = require('http');
44
const express = require('express');
55
const mysql = require('mysql2');
6+
const bunyan = require('bunyan');
67
const { S3Client, GetBucketLocationCommand } = require('@aws-sdk/client-s3');
78

89
const PORT = parseInt(process.env.SAMPLE_APP_PORT || '8000', 10);
910

1011
const app = express();
1112

13+
// Create bunyan logger
14+
const logger = bunyan.createLogger({name: 'express-app', level: 'info'});
15+
1216
app.get('/healthcheck', (req, res) => {
13-
console.log(`/healthcheck called successfully`)
17+
logger.info('/healthcheck called successfully');
1418
res.send('healthcheck');
1519
});
1620

@@ -23,12 +27,14 @@ app.get('/outgoing-http-call', (req, res) => {
2327
const httpRequest = http.request(options, (rs) => {
2428
rs.setEncoding('utf8');
2529
rs.on('data', (result) => {
26-
console.log(`/outgoing-http-call called successfully`)
27-
res.send(`/outgoing-http-call called successfully`);
30+
const msg = '/outgoing-http-call called successfully';
31+
logger.info(msg);
32+
res.send(msg);
2833
});
2934
rs.on('error', (err) => {
30-
console.log(`/outgoing-http-call called with error: ${err}`)
31-
res.send(`/outgoing-http-call called with error: ${err}`);
35+
const msg = `/outgoing-http-call called with error: ${err}`;
36+
logger.error(msg);
37+
res.send(msg);
3238
});
3339
});
3440
httpRequest.end();
@@ -37,19 +43,26 @@ app.get('/outgoing-http-call', (req, res) => {
3743
app.get('/aws-sdk-call', async (req, res) => {
3844
const s3Client = new S3Client({ region: 'us-east-1' });
3945
const bucketName = 'e2e-test-bucket-name-' + (req.query.testingId || 'MISSING_ID');
46+
47+
// Add custom warning log for validation testing
48+
const warningMsg = "This is a custom log for validation testing";
49+
logger.warn(warningMsg);
50+
4051
try {
4152
await s3Client.send(
4253
new GetBucketLocationCommand({
4354
Bucket: bucketName,
4455
}),
4556
).then((data) => {
46-
console.log('/aws-sdk-call called successfully; UNEXPECTEDLY RETURNED DATA: ' + data);
47-
res.send('/aws-sdk-call called successfully; UNEXPECTEDLY RETURNED DATA: ' + data);
57+
const msg = '/aws-sdk-call called successfully; UNEXPECTEDLY RETURNED DATA: ' + data;
58+
logger.info(msg);
59+
res.send(msg);
4860
});
4961
} catch (e) {
5062
if (e instanceof Error) {
51-
console.log('/aws-sdk-call called successfully')
52-
res.send('/aws-sdk-call called successfully');
63+
const msg = '/aws-sdk-call called successfully';
64+
logger.info(msg);
65+
res.send(msg);
5366
}
5467
}
5568
});
@@ -66,14 +79,16 @@ app.get('/remote-service', (req, res) => {
6679
const request = http.request(options, (rs) => {
6780
rs.setEncoding('utf8');
6881
rs.on('data', (result) => {
69-
console.log(`/remote-service called successfully: ${result}`);
70-
res.send(`/remote-service called successfully: ${result}`);
82+
const msg = `/remote-service called successfully: ${result}`;
83+
logger.info(msg);
84+
res.send(msg);
7185
});
7286
});
7387
request.on('error', (err) => {
74-
console.log('/remote-service called with errors: ' + err.errors);
75-
res.send('/remote-service called with errors: ' + err.errors);
76-
})
88+
const msg = '/remote-service called with errors: ' + err.errors;
89+
logger.error(msg);
90+
res.send(msg);
91+
});
7792
request.end();
7893
});
7994

@@ -82,12 +97,14 @@ let makeAsyncCall = false;
8297
setInterval(() => {
8398
if (makeAsyncCall) {
8499
makeAsyncCall = false;
85-
console.log('Async call triggered by /client-call API');
100+
logger.info('Async call triggered by /client-call API');
86101

87102
const request = http.get('http://local-root-client-call', (rs) => {
88103
rs.setEncoding('utf8');
89104
rs.on('data', (result) => {
90-
res.send(`GET local-root-client-call response: ${result}`);
105+
const msg = `GET local-root-client-call response: ${result}`;
106+
logger.info(msg);
107+
res.send(msg);
91108
});
92109
});
93110
request.on('error', (err) => {}); // Expected
@@ -96,9 +113,9 @@ setInterval(() => {
96113
}, 5000); // Check every 5 seconds
97114

98115
app.get('/client-call', (req, res) => {
99-
res.send('/client-call called successfully');
100-
console.log('/client-call called successfully');
101-
116+
const msg = '/client-call called successfully';
117+
logger.info(msg);
118+
res.send(msg);
102119
// Trigger async call to generate telemetry for InternalOperation use case
103120
makeAsyncCall = true;
104121
});
@@ -115,8 +132,9 @@ app.get('/mysql', (req, res) => {
115132
// Connect to the database
116133
connection.connect((err) => {
117134
if (err) {
118-
console.log('/mysql called with an error: ', err.errors);
119-
return res.status(500).send('/mysql called with an error: ' + err.errors);
135+
const msg = '/mysql called with an error: ' + err.errors;
136+
logger.error(msg);
137+
return res.status(500).send(msg);
120138
}
121139

122140
// Perform a simple query
@@ -125,15 +143,19 @@ app.get('/mysql', (req, res) => {
125143
connection.end();
126144

127145
if (queryErr) {
128-
return res.status(500).send('Could not complete http request to RDS database:' + queryErr.message);
146+
const msg = 'Could not complete http request to RDS database:' + queryErr.message;
147+
logger.error(msg);
148+
return res.status(500).send(msg);
129149
}
130150

131151
// Send the query results as the response
132-
res.send(`/outgoing-http-call response: ${results}`);
152+
const msg = `/outgoing-http-call response: ${results}`;
153+
logger.info(msg);
154+
res.send(msg);
133155
});
134156
});
135157
});
136158

137159
app.listen(PORT, () => {
138-
console.log(`Listening for requests on http://localhost:${PORT}`);
160+
logger.info(`Listening for requests on http://localhost:${PORT}`);
139161
});

sample-apps/node/frontend-service/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@types/express": "^4.17.21",
1515
"@types/node": "^20.14.6",
1616
"express": "^4.21.2",
17-
"mysql2": "^3.11.0"
17+
"mysql2": "^3.11.0",
18+
"bunyan": "^1.8.15"
1819
}
1920
}
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
'use strict';
22

33
const express = require('express');
4+
const bunyan = require('bunyan');
45

56
const PORT = parseInt(process.env.SAMPLE_APP_PORT || '8001', 10);
67

78
const app = express();
89

10+
// Create bunyan logger
11+
const logger = bunyan.createLogger({name: 'remote-service', level: 'info'});
12+
913
app.get('/healthcheck', (req, res) => {
10-
console.log(`/healthcheck (remote-service) called successfully`);
11-
res.send('/healthcheck (remote-service) called successfully');
14+
const msg = '/healthcheck (remote-service) called successfully';
15+
logger.info(msg);
16+
res.send(msg);
1217
});
1318

1419
app.listen(PORT, () => {
15-
console.log(`Listening for requests on http://localhost:${PORT}`);
16-
});
20+
logger.info(`Listening for requests on http://localhost:${PORT}`);
21+
});

sample-apps/node/remote-service/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@types/node": "^20.14.6",
1616
"express": "^4.21.2",
1717
"mysql2": "^3.11.0",
18-
"nodemon": "^3.1.4"
18+
"nodemon": "^3.1.4",
19+
"bunyan": "^1.8.15"
1920
}
2021
}

validator/src/main/resources/expected-data-template/dotnet/eks/linux/aws-sdk-call-trace.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "^{{serviceName}}$",
33
"http": {
44
"request": {
5-
"url": "^{{endpoint}}/aws-sdk-call(?:\\?ip=Redacted&testingId=Redacted)?$",
5+
"url": "^{{endpoint}}/aws-sdk-call(?:\\?{1,2}ip=Redacted&testingId=Redacted)?$",
66
"method": "^GET$"
77
}
88
},

validator/src/main/resources/expected-data-template/dotnet/eks/linux/remote-service-trace.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "^{{serviceName}}$",
33
"http": {
44
"request": {
5-
"url": "^{{endpoint}}/remote-service$",
5+
"url": "^{{endpoint}}/remote-service(?:\\?{1,2}ip=Redacted&testingId=Redacted)?$",
66
"method": "^GET$"
77
}
88
},

0 commit comments

Comments
 (0)