-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
447 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,6 @@ script: | |
- yarn --version | ||
- yarn check --integrity | ||
- yarn test | ||
before_install: | ||
- yarn global add greenkeeper-lockfile@1 | ||
before_script: greenkeeper-lockfile-update | ||
after_script: greenkeeper-lockfile-upload | ||
deploy: | ||
provider: npm | ||
email: [email protected] | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
'use strict' | ||
|
||
let Logger = require('./log/Logger'); | ||
Logger.express = require('./log/express'); | ||
|
||
module.exports = Logger; | ||
module.exports = { | ||
Logger: require('./log/Logger'), | ||
LoggingConfig: require('./log/config'), | ||
RequestTracing: require('./log/tracing/requestTracing'), | ||
RequestTracingHeaders: require('./log/tracing/headers'), | ||
Express: require('./log/express') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
REQUEST_ID_HEADER: 'Request-Id', | ||
ORIGIN_REQUEST_ID_HEADER: 'Origin-Request-Id', | ||
ROOT_REQUEST_ID_HEADER: 'Root-Request-Id' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict' | ||
|
||
const { createNamespace } = require('continuation-local-storage') | ||
|
||
const INITIAL_REQUEST = 'initialRequest' | ||
|
||
const clsNamespace = createNamespace('uk.gov.hmcts.reform.tracing.localStorage') | ||
|
||
class LocalStorage { | ||
static proceedWithinLocalStorageContext (req, res, next) { | ||
clsNamespace.run(() => { | ||
clsNamespace.bindEmitter(req) | ||
clsNamespace.bindEmitter(res) | ||
clsNamespace.set(INITIAL_REQUEST, req) | ||
next() | ||
}) | ||
} | ||
|
||
static retrieveInitialRequest () { | ||
return clsNamespace.get(INITIAL_REQUEST) | ||
} | ||
} | ||
|
||
module.exports = LocalStorage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict' | ||
|
||
const uuid = require('uuid') | ||
|
||
const LocalStorage = require('./localStorage') | ||
const { REQUEST_ID_HEADER, ROOT_REQUEST_ID_HEADER, ORIGIN_REQUEST_ID_HEADER } = require('./headers') | ||
|
||
function setInitialRequestTracingHeaders (req) { | ||
const id = uuid() | ||
req.headers[REQUEST_ID_HEADER] = id | ||
req.headers[ROOT_REQUEST_ID_HEADER] = id | ||
req.headers[ORIGIN_REQUEST_ID_HEADER] = undefined | ||
} | ||
|
||
function tracingHeadersNotPresentOrInvalid (req) { | ||
return notUUID(req.headers[REQUEST_ID_HEADER]) | ||
|| notUUID(req.headers[ROOT_REQUEST_ID_HEADER]) | ||
|| notUUID(req.headers[ORIGIN_REQUEST_ID_HEADER]) | ||
} | ||
|
||
function notUUID (uuidString) { | ||
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ | ||
return !UUID_REGEX.test(uuidString) | ||
} | ||
|
||
class RequestTracing { | ||
static middleware (req, res, next) { | ||
if (tracingHeadersNotPresentOrInvalid(req)) { | ||
setInitialRequestTracingHeaders(req) | ||
} | ||
LocalStorage.proceedWithinLocalStorageContext(req, res, next) | ||
} | ||
|
||
static getInitialRequest () { | ||
return LocalStorage.retrieveInitialRequest() | ||
} | ||
|
||
static getRootRequestId () { | ||
return RequestTracing.getInitialRequest().headers[ROOT_REQUEST_ID_HEADER] | ||
} | ||
|
||
static getCurrentRequestId () { | ||
return RequestTracing.getInitialRequest().headers[REQUEST_ID_HEADER] | ||
} | ||
|
||
static createNextRequestId () { | ||
return uuid() | ||
} | ||
} | ||
|
||
module.exports = RequestTracing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* global describe, it */ | ||
|
||
const expect = require('chai').expect; | ||
|
||
const AccessLogger = require('../../log/express').AccessLoggingHandler; | ||
const Logger = require('../../log/Logger') | ||
|
||
describe('AccessLogger', () => { | ||
it('should have a default logger', () => { | ||
const accessLogger = new AccessLogger() | ||
expect(accessLogger.logger).to.be.instanceOf(Logger) | ||
}) | ||
|
||
it('should have a default formatter', () => { | ||
const accessLogger = new AccessLogger() | ||
expect(accessLogger.formatter).to.be.instanceOf(Function) | ||
}) | ||
|
||
it('should have a default level function', () => { | ||
const accessLogger = new AccessLogger() | ||
expect(accessLogger.level).to.be.instanceOf(Function) | ||
}) | ||
}) |
Oops, something went wrong.