hydra-express icon indicating copy to clipboard operation
hydra-express copied to clipboard

Use module logging utility

Open tylerhutcherson opened this issue 3 years ago • 5 comments

An error in my Node JS application is throwing a hydra-express related exception (and covering up the real issue on my end):

TypeError: this.appLogger.fatal is not a function
    at /usr/src/app/node_modules/hydra-express/index.js:487:26
    at Layer.handle_error (/usr/src/app/node_modules/express/lib/router/layer.js:71:5)
    at trim_prefix (/usr/src/app/node_modules/express/lib/router/index.js:315:13)
    at /usr/src/app/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/usr/src/app/node_modules/express/lib/router/index.js:335:12)
    at next (/usr/src/app/node_modules/express/lib/router/index.js:275:10)
    at Layer.handle_error (/usr/src/app/node_modules/express/lib/router/layer.js:67:12)
    at trim_prefix (/usr/src/app/node_modules/express/lib/router/index.js:315:13)
    at /usr/src/app/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/usr/src/app/node_modules/express/lib/router/index.js:335:12)
    at next (/usr/src/app/node_modules/express/lib/router/index.js:275:10)
    at Layer.handle_error (/usr/src/app/node_modules/express/lib/router/layer.js:67:12)
    at trim_prefix (/usr/src/app/node_modules/express/lib/router/index.js:315:13)
    at /usr/src/app/node_modules/express/lib/router/index.js:284:7
    at param (/usr/src/app/node_modules/express/lib/router/index.js:354:14)
    at param (/usr/src/app/node_modules/express/lib/router/index.js:365:14)

Based on the trace, I believe the culprit is here: https://github.com/pnxtech/hydra-express/blob/b4871209d81aa19c1b402c84e0cc6a4593d8a3b4/index.js#L487 and should use this.log('fatal', {msg}) instead.

We are running with the following dependencies:

  "dependencies": {
    "redis": "2.8.0",
    "hydra-express": "1.8.3",
    "hydra-express-plugin-jwt-simple-auth": "0.1.0",
    "hydra-plugin-hls": "0.2.6",
    "node-fetch": "2.6.1"
  },

tylerhutcherson avatar Nov 23 '21 16:11 tylerhutcherson

@cjus Our app in question is already using the following package.json:

{
  "name": "shopify-webhooks-v1-svcs",
  "version": "0.1.3",
  "description": "Shopify Webhooks",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "redis": "2.8.0",
    "hydra-express": "1.8.3",
    "hydra-express-plugin-jwt-simple-auth": "0.1.0",
    "hydra-plugin-hls": "0.2.6",
    "node-fetch": "2.6.1"
  },
  "devDependencies": {
    "eslint": "7.15.0",
    "eslint-config-google": "0.14.0"
  }
}

tylerhutcherson avatar Nov 29 '21 15:11 tylerhutcherson

Looks like our app has the dependency, but the hydra-plugin-hls is not getting loaded/configured for us with hydraExpress. Our app has the following imports:

 const hydraExpress = require('hydra-express');
 const express = hydraExpress.getExpress();
 const hydra = hydraExpress.getHydra();
 const ServerResponse = hydra.getServerResponseHelper();
 const serverResponse = new ServerResponse;

 const api = new express.Router();

Am I correct that the proper import for hls plugin would be:

 const hydraExpress = require('hydra-express');
 const HydraLogPlugin = require('hydra-plugin-hls/hydra-express');
 hydraExpress.use(new HydraLogPlugin);

 const express = hydraExpress.getExpress();
 const hydra = hydraExpress.getHydra();
 const ServerResponse = hydra.getServerResponseHelper();
 const serverResponse = new ServerResponse;

 const api = new express.Router();

tylerhutcherson avatar Nov 29 '21 15:11 tylerhutcherson

I tested this update on our app, yet I still get the same error thrown by the hydra-express lib above.

tylerhutcherson avatar Dec 01 '21 13:12 tylerhutcherson

@tylerhutcherson is there any chance that your exception is occurring before the logging plugin is bound? Happy to help debug this via zoom. You have my contact info.

cjus avatar Dec 01 '21 17:12 cjus

@tylerhutcherson is there any chance that your exception is occurring before the logging plugin is bound? Happy to help debug this via zoom. You have my contact info.

It appears the true exception under the hood was an express PayloadTooLargeError described here. This was being covered up by the error posted above. When I removed the hydra logging plugin entirely, the exception passed through, enabling us to debug the real issue.

However - the error above seems to happen when there is a fatal log-level error inside the middleware.

This is currently non-blocking for us at the moment, however, I can leave this open if you want, or we can take the discussion offline and report back.

tylerhutcherson avatar Dec 08 '21 19:12 tylerhutcherson