Skip to content

Commit a7e1dd3

Browse files
committed
feat: added is_http boolean prop to metadata defaults
1 parent 30d794d commit a7e1dd3

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Here's an example object parsed:
6666
{
6767
"id": "5d126d86160cea56950f80a9",
6868
"timestamp": "2019-06-25T18:52:54.000Z",
69+
"is_http": true,
6970
"request": {
7071
"method": "POST",
7172
"query": {
@@ -132,6 +133,7 @@ A few extra details about the above parsed properties:
132133

133134
* `id` (String) - is a newly created BSON ObjectId used to uniquely identify this log
134135
* `timestamp` (String) - is the [ISO-8601][] date time string parsed from the `id` (thanks to MongoDB BSON `ObjectID.getTimestamp` method)
136+
* `is_http` (Boolean) - defaults to `true` to indicate that this was a parsed HTTP request
135137
* `duration` (Number) - is the number of milliseconds that `parseRequest` took to parse the request object (note that this uses `process.hrtime` which this package polyfills thanks to [browser-process-hrtime][])
136138
* `user` (Object) - is parsed from the user object on `req.user` automatically (e.g. you are using [passport][]):
137139
* `ip_address` (String) - IP address parsed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@commitlint/config-conventional": "^17.3.0",
4949
"@koa/multer": "^3.0.2",
5050
"@koa/router": "^12.0.0",
51+
"@ladjs/multer": "2.0.0-rc.5",
5152
"ava": "5.1.0",
5253
"axe": "^11.0.0",
5354
"babelify": "^10.0.0",
@@ -60,15 +61,13 @@
6061
"eslint-plugin-node": "^11.1.0",
6162
"express": "^4.18.2",
6263
"express-request-id": "1.4.1",
63-
"fix-esm": "^1.0.1",
6464
"fixpack": "^4.0.0",
6565
"get-port": "5.1.1",
6666
"husky": "^8.0.2",
6767
"jsdom": "15.2.1",
6868
"koa": "^2.13.4",
6969
"koa-connect": "^2.1.0",
7070
"lint-staged": "^13.0.3",
71-
"multer": "2.0.0-rc.4",
7271
"nyc": "^15.1.0",
7372
"remark-cli": "^11.0.0",
7473
"remark-preset-github": "^4.0.4",

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,10 @@ const parseRequest = (config = {}) => {
441441
// NOTE: regarding the naming convention of `timestamp`, it seems to be the
442442
// most widely used and supported property name across logging services
443443
//
444-
timestamp: id.getTimestamp().toISOString()
444+
timestamp: id.getTimestamp().toISOString(),
445+
// NOTE: this was added in v5.1.0 in order for us to look at logs
446+
// and easily determine which were requests by boolean value
447+
is_http: true
445448
};
446449

447450
if (ctx || req) result.request = {};

test/express.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('node:path');
22

33
const test = require('ava');
44
const express = require('express');
5-
const multer = require('fix-esm').require('multer').default;
5+
const multer = require('@ladjs/multer');
66
const requestId = require('express-request-id');
77
const requestReceived = require('request-received');
88
const responseTime = require('response-time');

0 commit comments

Comments
 (0)