Comparing version 0.5.0 to 0.6.1
@@ -37,5 +37,2 @@ module.exports = | ||
/******/ | ||
/******/ // identity function for calling harmony imports with the correct context | ||
/******/ __webpack_require__.i = function(value) { return value; }; | ||
/******/ | ||
/******/ // define getter function for harmony exports | ||
@@ -68,3 +65,3 @@ /******/ __webpack_require__.d = function(exports, name, getter) { | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 8); | ||
/******/ return __webpack_require__(__webpack_require__.s = 3); | ||
/******/ }) | ||
@@ -76,3 +73,3 @@ /************************************************************************/ | ||
const pkg = __webpack_require__(9) | ||
const pkg = __webpack_require__(12) | ||
const uuid = __webpack_require__(1) | ||
@@ -128,23 +125,124 @@ const https = __webpack_require__(2) | ||
/* 3 */ | ||
/***/ (function(module, exports) { | ||
/***/ (function(module, exports, __webpack_require__) { | ||
function Callback (generateLog, callback) { | ||
if (typeof(callback) !== 'function') { | ||
return undefined | ||
"use strict"; | ||
const dns = __webpack_require__(4) | ||
const setConfig = __webpack_require__(5) | ||
const Context = __webpack_require__(9) | ||
const Callback = __webpack_require__(10) | ||
const Report = __webpack_require__(11) | ||
const globals = __webpack_require__(0) | ||
function makeDnsPromise(host) { | ||
return new Promise((resolve, reject) => { | ||
dns.lookup(host, (err, address) => { | ||
if (err) { | ||
reject(err) | ||
} | ||
resolve(address) | ||
}) | ||
}) | ||
} | ||
function setupTimeoutCapture(config, report, context) { | ||
if (config.timeoutWindow < 1) { | ||
return | ||
} | ||
return (err, data) => { | ||
generateLog(err, () => { | ||
callback.apply(callback, [err, data]) | ||
var endTime = 599900 /* Maximum execution: 100ms short of 5 minutes */ | ||
if (config.timeoutWindow > 0 && context && context.getRemainingTimeInMillis) { | ||
endTime = Math.max(0, context.getRemainingTimeInMillis() - config.timeoutWindow) | ||
} | ||
return setTimeout(() => { | ||
report.send(new Error("Timeout Exceeded."), function noop() {}) | ||
}, endTime) | ||
} | ||
module.exports = function(options) { | ||
var fn = function(func) { | ||
fn.metricsQueue = [] | ||
const config = setConfig(options) | ||
if (!config.clientId) { | ||
// No-op if user doesn't set an IOpipe token. | ||
return func | ||
} | ||
/* resolve DNS early on coldstarts */ | ||
var dnsPromise = makeDnsPromise(config.host) | ||
return function() { | ||
fn.metricsQueue = [] | ||
var args = [].slice.call(arguments) | ||
if (!globals.COLDSTART) { | ||
/* Get an updated DNS record. */ | ||
dnsPromise = makeDnsPromise(config.host) | ||
} | ||
var startTime = process.hrtime() | ||
const report = new Report(config, args[1], startTime, fn.metricsQueue, dnsPromise) | ||
var timeout = setupTimeoutCapture(config, report, args[1]) | ||
var callback = (err, cb) => { | ||
if (timeout) { clearTimeout(timeout) } | ||
report.send(err, cb) | ||
} | ||
/* Mangle arguments, wrapping callbacks. */ | ||
args[1] = Context(callback, args[1]) | ||
args[2] = Callback(callback, args[2]) | ||
try { | ||
return func.apply(this, args) | ||
} | ||
catch (err) { | ||
clearTimeout(timeout) | ||
report.send(err, function noop() {}) | ||
return undefined | ||
} | ||
} | ||
} | ||
// Alias decorate to the wrapper function | ||
fn.decorate = fn | ||
fn.log = function(name, value) { | ||
var numberValue, stringValue | ||
if (typeof value === 'number') { | ||
numberValue = value | ||
} else { | ||
if(typeof value === 'object') { | ||
JSON.stringify(value) | ||
} else { | ||
stringValue = String(value) | ||
} | ||
} | ||
fn.metricsQueue.push({ | ||
name: name, | ||
n: numberValue, | ||
s: stringValue | ||
}) | ||
fn.VERSION = globals.VERSION | ||
} | ||
return fn | ||
} | ||
module.exports = Callback | ||
/***/ }), | ||
/* 4 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("dns"); | ||
/***/ }), | ||
/* 4 */ | ||
/* 5 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
const collector = __webpack_require__(10) | ||
const collector = __webpack_require__(6) | ||
const getHostname = collector.getHostname, | ||
@@ -184,5 +282,53 @@ getCollectorPath = collector.getCollectorPath | ||
/***/ }), | ||
/* 5 */ | ||
/* 6 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
var url = __webpack_require__(7) | ||
var path = __webpack_require__(8) | ||
function getCollectorPath(baseUrl) { | ||
if (!baseUrl) { | ||
return '/v0/event' | ||
} | ||
var eventURL = url.parse(baseUrl) | ||
eventURL.pathname = path.join(eventURL.pathname, 'v0/event') | ||
eventURL.path = eventURL.search ? eventURL.pathname + eventURL.search : eventURL.pathname | ||
return eventURL.path | ||
} | ||
function getHostname(configUrl) { | ||
if (configUrl) { | ||
return url.parse(configUrl).hostname | ||
} | ||
const supportedRegions = ['ap-southeast-2', 'eu-west-1', 'us-east-2', 'us-west-1', 'us-west-2']; | ||
var regionString = ''; | ||
if (supportedRegions.indexOf(process.env.AWS_REGION) > -1){ | ||
regionString = `.${process.env.AWS_REGION}`; | ||
} | ||
return `metrics-api${regionString}.iopipe.com`; | ||
} | ||
module.exports = { | ||
getHostname, | ||
getCollectorPath | ||
} | ||
/***/ }), | ||
/* 7 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("url"); | ||
/***/ }), | ||
/* 8 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("path"); | ||
/***/ }), | ||
/* 9 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
@@ -256,3 +402,21 @@ | ||
/***/ }), | ||
/* 6 */ | ||
/* 10 */ | ||
/***/ (function(module, exports) { | ||
function Callback (generateLog, callback) { | ||
if (typeof(callback) !== 'function') { | ||
return undefined | ||
} | ||
return (err, data) => { | ||
generateLog(err, () => { | ||
callback.apply(callback, [err, data]) | ||
}) | ||
} | ||
} | ||
module.exports = Callback | ||
/***/ }), | ||
/* 11 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -264,4 +428,4 @@ | ||
const globals = __webpack_require__(0) | ||
const system = (process.platform === 'linux') ? __webpack_require__(12) : __webpack_require__(11) | ||
const os = __webpack_require__(15) | ||
const system = (process.platform === 'linux') ? __webpack_require__(14) : __webpack_require__(16) | ||
const os = __webpack_require__(17) | ||
const https = __webpack_require__(2) | ||
@@ -458,127 +622,8 @@ const log = console.log | ||
/***/ }), | ||
/* 7 */ | ||
/* 12 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("dns"); | ||
/***/ }), | ||
/* 8 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
const dns = __webpack_require__(7) | ||
const setConfig = __webpack_require__(4) | ||
const Context = __webpack_require__(5) | ||
const Callback = __webpack_require__(3) | ||
const Report = __webpack_require__(6) | ||
const globals = __webpack_require__(0) | ||
function makeDnsPromise(host) { | ||
return new Promise((resolve, reject) => { | ||
dns.lookup(host, (err, address) => { | ||
if (err) { | ||
reject(err) | ||
} | ||
resolve(address) | ||
}) | ||
}) | ||
} | ||
function setupTimeoutCapture(config, report, context) { | ||
if (config.timeoutWindow < 1) { | ||
return | ||
} | ||
var endTime = 599900 /* Maximum execution: 100ms short of 5 minutes */ | ||
if (config.timeoutWindow > 0 && context && context.getRemainingTimeInMillis) { | ||
endTime = Math.max(0, context.getRemainingTimeInMillis() - config.timeoutWindow) | ||
} | ||
return setTimeout(() => { | ||
report.send(new Error("Timeout Exceeded."), function noop() {}) | ||
}, endTime) | ||
} | ||
module.exports = function(options) { | ||
var fn = function(func) { | ||
fn.metricsQueue = [] | ||
const config = setConfig(options) | ||
if (!config.clientId) { | ||
// No-op if user doesn't set an IOpipe token. | ||
return func | ||
} | ||
/* resolve DNS early on coldstarts */ | ||
var dnsPromise = makeDnsPromise(config.host) | ||
return function() { | ||
fn.metricsQueue = [] | ||
var args = [].slice.call(arguments) | ||
if (!globals.COLDSTART) { | ||
/* Get an updated DNS record. */ | ||
dnsPromise = makeDnsPromise(config.host) | ||
} | ||
var startTime = process.hrtime() | ||
const report = new Report(config, args[1], startTime, fn.metricsQueue, dnsPromise) | ||
var timeout = setupTimeoutCapture(config, report, args[1]) | ||
var callback = (err, cb) => { | ||
if (timeout) { clearTimeout(timeout) } | ||
report.send(err, cb) | ||
} | ||
/* Mangle arguments, wrapping callbacks. */ | ||
args[1] = Context(callback, args[1]) | ||
args[2] = Callback(callback, args[2]) | ||
try { | ||
return func.apply(this, args) | ||
} | ||
catch (err) { | ||
clearTimeout(timeout) | ||
report.send(err, function noop() {}) | ||
return undefined | ||
} | ||
} | ||
} | ||
// Alias decorate to the wrapper function | ||
fn.decorate = fn | ||
fn.log = function(name, value) { | ||
var numberValue, stringValue | ||
if (typeof value === 'number') { | ||
numberValue = value | ||
} else { | ||
if(typeof value === 'object') { | ||
JSON.stringify(value) | ||
} else { | ||
stringValue = String(value) | ||
} | ||
} | ||
fn.metricsQueue.push({ | ||
name: name, | ||
n: numberValue, | ||
s: stringValue | ||
}) | ||
fn.VERSION = globals.VERSION | ||
} | ||
return fn | ||
} | ||
/***/ }), | ||
/* 9 */ | ||
/***/ (function(module, exports) { | ||
module.exports = { | ||
"name": "iopipe", | ||
"version": "0.5.0", | ||
"version": "0.6.1", | ||
"description": "IOpipe Lambda Analytics & Tracing Agent", | ||
@@ -627,79 +672,13 @@ "main": "dist/iopipe.js", | ||
/***/ }), | ||
/* 10 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
/* 13 */ | ||
/***/ (function(module, exports) { | ||
var url = __webpack_require__(17) | ||
var path = __webpack_require__(16) | ||
module.exports = require("crypto"); | ||
function getCollectorPath(baseUrl) { | ||
if (!baseUrl) { | ||
return '/v0/event' | ||
} | ||
var eventURL = url.parse(baseUrl) | ||
eventURL.pathname = path.join(eventURL.pathname, 'v0/event') | ||
eventURL.path = eventURL.search ? eventURL.pathname + eventURL.search : eventURL.pathname | ||
return eventURL.path | ||
} | ||
function getHostname(configUrl) { | ||
if (configUrl) { | ||
return url.parse(configUrl).hostname | ||
} | ||
const supportedRegions = ['ap-southeast-2', 'eu-west-1', 'us-east-2', 'us-west-1', 'us-west-2']; | ||
var regionString = ''; | ||
if (supportedRegions.indexOf(process.env.AWS_REGION) > -1){ | ||
regionString = `.${process.env.AWS_REGION}`; | ||
} | ||
return `metrics-api${regionString}.iopipe.com`; | ||
} | ||
module.exports = { | ||
getHostname, | ||
getCollectorPath | ||
} | ||
/***/ }), | ||
/* 11 */ | ||
/* 14 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
var uuid = __webpack_require__(1) | ||
var fs = __webpack_require__(15) | ||
function readstat() { | ||
return Promise.resolve({ | ||
utime: 0, | ||
stime: 0, | ||
cutime: 0, | ||
cstime: 0, | ||
rss: 0 | ||
}) | ||
} | ||
function readstatus() { | ||
var mem = process.memoryUsage() | ||
return Promise.resolve({ | ||
FDSize: 0, | ||
Threads: 1, | ||
VmRSS: mem.rss / 1024, | ||
}) | ||
} | ||
function readbootid() { | ||
return Promise.resolve(uuid()) | ||
} | ||
module.exports = { | ||
readstat, | ||
readstatus, | ||
readbootid | ||
} | ||
/***/ }), | ||
/* 12 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
var fs = __webpack_require__(14) | ||
function readstat(pid) { | ||
@@ -768,25 +747,43 @@ return new Promise((resolve, reject) => { | ||
/***/ }), | ||
/* 13 */ | ||
/* 15 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("crypto"); | ||
module.exports = require("fs"); | ||
/***/ }), | ||
/* 14 */ | ||
/***/ (function(module, exports) { | ||
/* 16 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
module.exports = require("fs"); | ||
var uuid = __webpack_require__(1) | ||
/***/ }), | ||
/* 15 */ | ||
/***/ (function(module, exports) { | ||
function readstat() { | ||
return Promise.resolve({ | ||
utime: 0, | ||
stime: 0, | ||
cutime: 0, | ||
cstime: 0, | ||
rss: 0 | ||
}) | ||
} | ||
module.exports = require("os"); | ||
function readstatus() { | ||
var mem = process.memoryUsage() | ||
return Promise.resolve({ | ||
FDSize: 0, | ||
Threads: 1, | ||
VmRSS: mem.rss / 1024, | ||
}) | ||
} | ||
/***/ }), | ||
/* 16 */ | ||
/***/ (function(module, exports) { | ||
function readbootid() { | ||
return Promise.resolve(uuid()) | ||
} | ||
module.exports = require("path"); | ||
module.exports = { | ||
readstat, | ||
readstatus, | ||
readbootid | ||
} | ||
/***/ }), | ||
@@ -796,5 +793,5 @@ /* 17 */ | ||
module.exports = require("url"); | ||
module.exports = require("os"); | ||
/***/ }) | ||
/******/ ]); |
{ | ||
"name": "iopipe", | ||
"version": "0.5.0", | ||
"version": "0.6.1", | ||
"description": "IOpipe Lambda Analytics & Tracing Agent", | ||
@@ -5,0 +5,0 @@ "main": "dist/iopipe.js", |
34528
663