Skip to content

Commit

Permalink
(feature) Add local server address and port to node ingestor (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
AHarmlessPyro authored Oct 17, 2022
1 parent 964eb53 commit ac4fc63
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
9 changes: 4 additions & 5 deletions ingestors/node/src/modules/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function initialize({ key, host, pool }) {
const data = JSON.stringify({
request: {
url: {
host: _req.hostname,
host: _req.socket.remoteAddress,
path: _req.route.path,
parameters: Object.entries(_req.query).map(([k, v]) => ({ name: k, value: v })),
},
Expand All @@ -30,7 +30,7 @@ function initialize({ key, host, pool }) {
method: _req.method,
},
response: {
url: `${_req.socket.remoteAddress}:${_req.socket.remotePort}`,
url: `${_req.socket.localAddress}:${_req.socket.localPort}`,
status: _res.statusCode,
headers: Object.entries(_res.getHeaders()).map(([k, v]) => ({ name: k, value: v })),
body: responseBody,
Expand All @@ -40,9 +40,8 @@ function initialize({ key, host, pool }) {
incoming: true,
source: _req.socket.remoteAddress,
sourcePort: _req.socket.remotePort,
// TODO : Add destination
destination: "server.hostname",
destinationPort: "server.port",
destination: _res.socket.localAddress,
destinationPort: _res.socket.localPort,
}
})

Expand Down
11 changes: 5 additions & 6 deletions ingestors/node/src/modules/fastify.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ function initialize({ key, host, pool }) {
{
request: {
url: {
host: request.hostname,
host: request.raw.socket.remoteAddress,
path: request.routerPath,
parameters: Object.entries(request.query).map(([k, v]) => ({ name: k, value: v })),
},
headers: Object.entries(request.headers).map(([k, v]) => ({ name: k, value: v })),
body: request.body || "No Body",
body: request.body || "",
method: request.method,
},
response: {
url: `${response.raw.socket.remoteAddress}:${response.raw.socket.remotePort}`,
url: `${response.raw.socket.localAddress}:${response.raw.socket.localPort}`,
status: response.statusCode,
headers: Object.entries(response.headers).map(([k, v]) => ({ name: k, value: v })),
body: response.body,
Expand All @@ -41,9 +41,8 @@ function initialize({ key, host, pool }) {
incoming: true,
source: request.raw.socket.remoteAddress,
sourcePort: request.raw.socket.remotePort,
// TODO : Add destination
destination: "server.hostname",
destinationPort: "server.port",
destination: response.raw.socket.localAddress,
destinationPort: response.raw.socket.localPort,
}
}
)
Expand Down
11 changes: 5 additions & 6 deletions ingestors/node/src/modules/koa.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ function initialize({ key, host, pool }) {
{
request: {
url: {
host: ctx.request.hostname,
host: ctx.response.socket.remoteAddress,
path: ctx.path,
parameters: Object.entries(ctx.query).map(([k, v]) => ({ name: k, value: v })),
},
headers: Object.entries(ctx.request.headers).map(([k, v]) => ({ name: k, value: v })),
body: ctx.request.body || "No Body",
body: ctx.request.body || "",
method: ctx.request.method,
},
response: {
url: `${ctx.response.socket.remoteAddress}:${ctx.response.socket.remotePort}`,
url: `${ctx.response.socket.localAddress}:${ctx.response.socket.localPort}`,
status: ctx.response.statusCode,
headers: Object.entries(ctx.response.headers).map(([k, v]) => ({ name: k, value: v })),
body: ctx.body,
Expand All @@ -42,9 +42,8 @@ function initialize({ key, host, pool }) {
incoming: true,
source: ctx.request.socket.remoteAddress,
sourcePort: ctx.request.socket.remotePort,
// TODO : Add destination
destination: "server.hostname",
destinationPort: "server.port",
destination: ctx.request.socket.localAddress,
destinationPort: ctx.request.socket.localPort,
}
}
)
Expand Down

0 comments on commit ac4fc63

Please sign in to comment.