New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@iopipe/trace

Package Overview
Dependencies
Maintainers
8
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iopipe/trace - npm Package Compare versions

Comparing version 1.4.1 to 1.5.0

dist/plugins/redis.js

33

dist/addToReport.js

@@ -7,4 +7,3 @@ 'use strict';

exports.addToReport = addToReport;
exports.addHttpTracesToReport = addHttpTracesToReport;
exports.addIoRedisTracesToReport = addIoRedisTracesToReport;
exports.addTraceData = addTraceData;

@@ -26,7 +25,10 @@ var _flat = require('flat');

function addHttpTracesToReport(plugin) {
const { autoHttpData: { timeline = {} } } = plugin;
function addTraceData(plugin, type) {
const namespace = `${type.config}Data`;
const { [namespace]: { timeline = {} } } = plugin;
const { report: { report = {} } = {} } = plugin.invocationInstance;
Object.keys(plugin.autoHttpData.data).forEach(id => {
const obj = (0, _flat.unflatten)(plugin.autoHttpData.data[id] || {});
Object.keys(plugin[namespace].data).forEach(id => {
const obj = (0, _flat.unflatten)(plugin[namespace].data[id] || {});
if (obj.request) {

@@ -45,21 +47,4 @@ obj.request.headers = headersObjToArray(obj.request.headers);

obj.duration = measureMark.duration || 0;
report.httpTraceEntries.push(obj);
report[type.entries].push(obj);
});
}
function addIoRedisTracesToReport(plugin) {
const { autoIoRedisData: { timeline = {} } } = plugin;
const { report: { report = {} } = {} } = plugin.invocationInstance;
Object.keys(plugin.autoIoRedisData.data).forEach(id => {
const obj = (0, _flat.unflatten)(plugin.autoIoRedisData.data[id] || {});
// use start mark for startTime in case the call did not finish / no callback
// and we do not have a measurement
const [startMark = {}] = timeline.getEntriesByName(`start:${id}`) || [];
const [measureMark = {}] = timeline.getEntriesByName(`measure:${id}`) || [];
obj.timestamp = startMark.timestamp || 0;
obj.startTime = startMark.startTime || 0;
obj.duration = measureMark.duration || 0;
report.dbTraceEntries.push(obj);
});
}

@@ -13,7 +13,22 @@ 'use strict';

var _https = require('./plugins/https');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _ioredis = require('./plugins/ioredis');
const plugins = {
https: {
config: 'autoHttp',
enabled: true,
entries: 'httpTraceEntries'
},
ioredis: {
config: 'autoIoRedis',
flag: 'IOPIPE_TRACE_IOREDIS',
entries: 'dbTraceEntries'
},
redis: {
config: 'autoRedis',
flag: 'IOPIPE_TRACE_REDIS',
entries: 'dbTraceEntries'
}
}; // eslint-disable-line import/extensions
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -26,5 +41,4 @@ function getBooleanFromEnv(key = '') {

return Boolean(process.env[key]);
} // eslint-disable-line import/extensions
}
function getConfig(config = {}) {

@@ -34,3 +48,4 @@ const {

autoHttp = { enabled: true },
autoIoRedis = { enabled: getBooleanFromEnv('IOPIPE_TRACE_IOREDIS') }
autoIoRedis = { enabled: getBooleanFromEnv('IOPIPE_TRACE_IOREDIS') },
autoRedis = { enabled: getBooleanFromEnv('IOPIPE_TRACE_REDIS') }
} = config;

@@ -45,2 +60,5 @@ return {

},
autoRedis: {
enabled: typeof autoRedis.enabled === 'boolean' ? autoRedis.enabled : getBooleanFromEnv('IOPIPE_TRACE_REDIS')
},
autoMeasure

@@ -59,2 +77,3 @@ };

// if so, measure
// console.log('NAMES', names);
names.forEach(name => {

@@ -72,16 +91,10 @@ if (name.match(/^(start):.+/)) {

function recordAutoHttpData(plugin) {
addTimelineMeasures(plugin, plugin.autoHttpData.timeline);
(0, _addToReport.addHttpTracesToReport)(plugin);
plugin.autoHttpData.timeline.clear();
plugin.autoHttpData.data = {};
function recordData(plugin, type) {
const namespace = `${plugins[type].config}Data`;
addTimelineMeasures(plugin, plugin[namespace].timeline);
(0, _addToReport.addTraceData)(plugin, plugins[type]);
plugin[namespace].timeline.clear();
plugin[namespace].data = {};
}
function recordAutoIoRedisData(plugin) {
addTimelineMeasures(plugin, plugin.autoIoRedisData.timeline);
(0, _addToReport.addIoRedisTracesToReport)(plugin);
plugin.autoIoRedisData.timeline.clear();
plugin.autoIoRedisData.data = {};
}
class TracePlugin {

@@ -98,21 +111,25 @@ constructor(config = {}, invocationInstance) {

};
if (this.config.autoHttp.enabled) {
this.autoHttpData = {
timeline: new _performanceNode2.default({ timestamp: true }),
// object to store data about traces that will make it into the report later
data: {},
config: this.config.autoHttp
};
(0, _https.wrap)(this.autoHttpData);
}
if (this.config.autoIoRedis.enabled) {
this.autoIoRedisData = {
timeline: new _performanceNode2.default({ timestamp: true }),
// object to store data about traces that will make it into the report later
data: {},
config: this.config.autoIoRedis
};
(0, _ioredis.wrap)(this.autoIoRedisData);
}
const context = this;
const pluginKeys = Object.keys(plugins);
pluginKeys.forEach(k => {
const conf = plugins[k].config;
const namespace = `${conf}Data`;
if (context.config[conf].enabled) {
// getting plugin; allows this to be loaded only if enabled.
const module = require(`./plugins/${k}`);
plugins[k].wrap = module.wrap;
plugins[k].unwrap = module.unwrap;
context[namespace] = {
timeline: new _performanceNode2.default({ timestamp: true }),
// object to store data about traces that will make it into the report later
data: {},
config: context.config[conf]
};
plugins[k].wrap(context[namespace]);
}
});
return this;

@@ -133,8 +150,13 @@ }

postInvoke() {
if (this.config.autoHttp.enabled) {
(0, _https.unwrap)();
}
if (this.config.autoIoRedis.enabled) {
(0, _ioredis.unwrap)();
}
const context = this;
const pluginKeys = Object.keys(plugins);
pluginKeys.forEach(k => {
const conf = plugins[k].config;
if (context.config[conf].enabled) {
if (context.config[conf].enabled) {
plugins[k].unwrap();
}
}
});
if (typeof this.invocationInstance.context.iopipe.label === 'function' && this.timeline.getEntries().length > 0) {

@@ -148,8 +170,10 @@ this.invocationInstance.context.iopipe.label('@iopipe/plugin-trace');

}
if (this.config.autoHttp.enabled) {
recordAutoHttpData(this);
}
if (this.config.autoIoRedis.enabled) {
recordAutoIoRedisData(this);
}
const context = this;
const pluginKeys = Object.keys(plugins);
pluginKeys.forEach(k => {
const conf = plugins[k].config;
if (this.config[conf].enabled) {
recordData(context, k);
}
});
(0, _addToReport.addToReport)(this);

@@ -156,0 +180,0 @@ }

@@ -34,3 +34,3 @@ 'use strict';

const createId = () => `redis-${(0, _v2.default)()}`;
const createId = () => `ioredis-${(0, _v2.default)()}`;

@@ -43,3 +43,2 @@ const filterRequest = (command, context) => {

const { hostname, port, connectionName, db } = context.options;
return {

@@ -46,0 +45,0 @@ command: name,

{
"name": "@iopipe/trace",
"version": "1.4.1",
"version": "1.5.0",
"description": "IOpipe plugin for tracing metrics",

@@ -14,3 +14,2 @@ "main": "dist/index.js",

"test": "iopipe-scripts test",
"testRedis": "yarn run jest src/plugins/ioredis.test.js --forceExit --verbose",
"validate": "iopipe-scripts validate"

@@ -40,3 +39,3 @@ },

"devDependencies": {
"@iopipe/core": "^1.x",
"@iopipe/core": "^1",
"@iopipe/scripts": "^1.4.1",

@@ -46,3 +45,5 @@ "aws-lambda-mock-context": "^3.0.0",

"got": "^8.3.1",
"ioredis": "^4",
"lodash": "^4.17.4",
"redis": "^2",
"superagent": "^3.8.3"

@@ -52,7 +53,6 @@ },

"flat": "^4.0.0",
"ioredis": "^4.9.0",
"isarray": "^2.0.4",
"lodash.pickby": "^4.6.0",
"performance-node": "^0.2.0",
"semver": "^6.0.0",
"performance-node": "^0",
"semver": "^6.3.0",
"shimmer": "^1.2.1",

@@ -59,0 +59,0 @@ "uuid": "^3.2.1"

@@ -111,5 +111,11 @@ # IOpipe Trace Plugin

```
#### `autoRedis` Automatically trace Redis commands using redis (node_redis)
Set the environment variable `IOPIPE_TRACE_REDIS` to `true`, and IOpipe will trace Redis commands automatically: which command, which key is being read or written, and information about the connection: hostname, port, and connection name (if defined in your connection options). Commands batched with multi/exec are traced individually, so you can measure individual performance within batch operations.
If you're using redis@2.5.3 or earlier, turn on auto-tracing with the `IOPIPE_TRACE_REDIS_CB` environment variable set to true.
#### `autoIoRedis` Automatically trace Redis commands using ioredis
Setting the environment variable `IOPIPE_TRACE_IOREDIS` to `true` for your function will enable automatic traces on Redis commands: the name of the command, name of the host, port, and connection (if defined in your connection options), and the key being written or read. Commands batched with multi/exec are traced individually, so you can measure individual performance within batch operations.
Set the environment variable `IOPIPE_TRACE_IOREDIS` to `true`, and your function will enable automatic traces on Redis commands: the name of the command, name of the host, port, and connection (if defined in your connection options), and the key being written or read. Commands batched with multi/exec are traced individually, so you can measure individual performance within batch operations.

@@ -116,0 +122,0 @@ #### `autoMeasure` (bool: optional = true)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc