Browse Source

feat(log): Log structured data about Placeholder requests

Structured logs allow later analysis with details like query parameters,
request time, etc.
pull/1220/head
Julian Simioni 6 years ago
parent
commit
92d15c6687
No known key found for this signature in database
GPG Key ID: B9EEB0C6EE0910A1
  1. 9
      controller/placeholder.js
  2. 7
      middleware/changeLanguage.js

9
controller/placeholder.js

@ -228,8 +228,17 @@ function setup(placeholderService, do_geometric_filters_apply, should_execute) {
return next(); return next();
} }
const initialTime = debugLog.beginTimer(req); const initialTime = debugLog.beginTimer(req);
const start = Date.now();
placeholderService(req, (err, results) => { placeholderService(req, (err, results) => {
logger.info('placeholder', {
response_time: Date.now() - start,
params: req.clean,
result_count: _.defaultTo(res.data, []).length,
text_length: _.get(req, 'clean.text.length', 0),
controller: 'placeholder',
});
if (err) { if (err) {
// push err.message or err onto req.errors // push err.message or err onto req.errors
req.errors.push( _.get(err, 'message', err)); req.errors.push( _.get(err, 'message', err));

7
middleware/changeLanguage.js

@ -32,6 +32,7 @@ function setup(service, should_execute) {
return next(); return next();
} }
const start = Date.now();
service(req, res, (err, translations) => { service(req, res, (err, translations) => {
// if there's an error, log it and bail // if there's an error, log it and bail
if (err) { if (err) {
@ -40,6 +41,12 @@ function setup(service, should_execute) {
return next(); return next();
} }
logger.info('language', {
response_time: Date.now() - start,
language: req.clean.lang.iso6391,
controller: 'language', //technically middleware, but this is consistent with other log lines
});
// otherwise, update all the docs with translations // otherwise, update all the docs with translations
updateDocs(req, res, _.defaultTo(translations, [])); updateDocs(req, res, _.defaultTo(translations, []));
next(); next();

Loading…
Cancel
Save