-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PP-4132 Added sub-segmenting to instrument the card_check request pat…
…h, middleware and controller - modified tests to add a @global stub for x-ray and continuation-local-storage that is not required in unit testing
- Loading branch information
Mark Bridgett
committed
Aug 29, 2018
1 parent
1262d86
commit 05c81e0
Showing
15 changed files
with
206 additions
and
96 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
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,26 +1,38 @@ | ||
'use strict' | ||
|
||
// NPM dependencies | ||
const AWSXRay = require('aws-xray-sdk') | ||
const {getNamespace} = require('continuation-local-storage') | ||
|
||
// local dependencies | ||
const views = require('../utils/views.js') | ||
const Charge = require('../models/charge.js') | ||
const chargeParam = require('../services/charge_param_retriever.js') | ||
const CORRELATION_HEADER = require('../utils/correlation_header.js').CORRELATION_HEADER | ||
const withAnalyticsError = require('../utils/analytics.js').withAnalyticsError | ||
|
||
// constants | ||
const clsXrayConfig = require('../../config/xray-cls') | ||
|
||
module.exports = (req, res, next) => { | ||
const chargeId = chargeParam.retrieve(req) | ||
|
||
const namespace = getNamespace(clsXrayConfig.nameSpaceName) | ||
const clsSegment = namespace.get(clsXrayConfig.segmentKeyName) | ||
if (!chargeId) { | ||
views.display(res, 'UNAUTHORISED', withAnalyticsError()) | ||
} else { | ||
req.chargeId = chargeId | ||
Charge(req.headers[CORRELATION_HEADER]).find(chargeId) | ||
.then(data => { | ||
req.chargeData = data | ||
next() | ||
}) | ||
.catch(() => { | ||
views.display(res, 'SYSTEM_ERROR', withAnalyticsError()) | ||
}) | ||
AWSXRay.captureAsyncFunc('Charge_find', function (subsegment) { | ||
Charge(req.headers[CORRELATION_HEADER]).find(chargeId) | ||
.then(data => { | ||
subsegment.close() | ||
req.chargeData = data | ||
next() | ||
}) | ||
.catch(() => { | ||
subsegment.close('error') | ||
views.display(res, 'SYSTEM_ERROR', withAnalyticsError()) | ||
}) | ||
}, clsSegment) | ||
} | ||
} |
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
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
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 |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
], | ||
"default": { | ||
"fixed_target": 1, | ||
"rate": 0.1 | ||
"rate": 0.01 | ||
}, | ||
"version": 1 | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.