Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (uri, opts, cb) => new Promise((resolve, reject) => {
const namespace = getNamespace(clsXrayConfig.nameSpaceName)
const clsSegment = namespace ? namespace.get(clsXrayConfig.segmentKeyName) : null
const args = [uri, opts, cb]
uri = args.find(arg => typeof arg === 'string')
opts = args.find(arg => typeof arg === 'object') || {}
cb = args.find(arg => typeof arg === 'function')
if (verb) opts.method = verb.toUpperCase()
if (uri && !opts.uri && !opts.url) opts.url = uri
const context = {
correlationId: correlator.getId(),
startTime: new Date(),
url: joinURL(lodash.get(opts, 'baseUrl', ''), opts.url),
method: opts.method,
description: opts.description,
service: opts.service
}
// Set headers and optional x-ray trace headers
lodash.set(opts, `headers.${CORRELATION_HEADER}`, context.correlationId)
if (clsSegment) {
const subSegment = opts.subSegment || new AWSXRay.Segment('_request_nbc', null, clsSegment.trace_id)
opts.headers['X-Amzn-Trace-Id'] = 'Root=' + clsSegment.trace_id + ';Parent=' + subSegment.id + ';Sampled=1'
}
opts.headers['Content-Type'] = opts.headers['Content-Type'] || 'application/json'
// Set up post response and error handling method
function getCorrelator () {
return {
get: correlator.getId,
with: correlator.withId,
bind: correlator.bindId
}
}
server.ext('onRequest', function (req, reply) {
req.headers['x-laabr-cid'] = req.headers[field] || req.id
return correlator.withId(req.headers['x-laabr-cid'], function () {
reply.continue()
})
})
}