Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rbi-nodejs-agent

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rbi-nodejs-agent - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

32

dist/index.js

@@ -190,23 +190,13 @@ "use strict";

}); }; },
errorHandler: function (_a) {
var Sentry = _a.Sentry;
return function (err, req, res, next) {
_this._endIntegrations();
if (_this.env === constants_1.Environments.DEBUG) {
return next(err);
}
/**
* Temporary Sentry integration
* TODO: remove this
*/
if (Sentry) {
Sentry.setTag("rebugit-traceId", _this.tracer.traceId);
}
var errorDomain = new ErrorDomain(_this.tracer.traceId, err);
_this.api.createError(_this.tracer, errorDomain).then();
logger.info("Ending trace with traceId: " + _this.tracer.traceId);
_this.clean();
next(err);
};
},
errorHandler: function () { return function (err, req, res, next) {
_this._endIntegrations();
if (_this.env === constants_1.Environments.DEBUG) {
return next(err);
}
var errorDomain = new ErrorDomain(_this.tracer.traceId, err);
_this.api.createError(_this.tracer, errorDomain).then();
logger.info("Ending trace with traceId: " + _this.tracer.traceId);
_this.clean();
next(err);
}; },
};

@@ -213,0 +203,0 @@ };

@@ -24,3 +24,2 @@ "use strict";

var shimmer = require("shimmer");
var stringify = require('flatted').stringify;
var Trace = require('../trace/Trace').Trace;

@@ -68,35 +67,61 @@ var logger = require('../logger');

};
HttpIntegration.prototype.getRequestObj = function (httpMock, correlationId) {
var data = this.tracesLoader.get(correlationId);
logger.info("correlationId: " + correlationId, this.namespace);
logger.info("trace loaded: " + data, this.namespace);
var emitter = new events.EventEmitter();
var resMock = httpMock.createResponse(emitter);
// @ts-ignore
resMock.on = function (type, cb) {
if (type === 'data') {
cb(Buffer.from(data.body));
}
if (type === 'end') {
cb();
}
};
// @ts-ignore
resMock.once = function (type, cb) {
if (type === 'end') {
cb();
}
};
resMock.statusCode = data.statusCode;
resMock.headers = data.headers;
resMock.statusMessage = data.statusMessage;
this.addExtraFieldsToRes(resMock, data);
return resMock;
};
HttpIntegration.prototype.wrap = function () {
var _this = this;
var integration = this;
return function (request) {
return function (options, callback) {
return function () {
var options = arguments[0];
var method = (options.method || 'GET').toUpperCase();
options = typeof options === 'string' ? url.parse(options) : options;
// @ts-ignore
var path = options.path || options.pathname || '/';
var correlationId = _this.getCorrelationId(method, path);
var correlationId = integration.getCorrelationId(method, path);
var originalCallback;
if (options.callback) {
originalCallback = options.callback;
}
else { // @ts-ignore
if (typeof arguments[1] === "function") {
originalCallback = arguments[1];
}
else if (arguments[2] && typeof arguments[2] === 'function') {
originalCallback = arguments[2];
}
}
try {
if (integration.env === 'debug') {
var data_1 = _this.tracesLoader.get(correlationId);
logger.info("correlationId: " + correlationId, _this.namespace);
logger.info("trace loaded: " + data_1, _this.namespace);
var httpMock_1 = new http_1.HttpMock();
var httpMock = new http_1.HttpMock();
var resMock_1 = integration.getRequestObj(httpMock, correlationId);
var wrappedCallback = function () {
var emitter = new events.EventEmitter();
var resMock = httpMock_1.createResponseMock(emitter);
process.nextTick(function () {
resMock.emit('data', data_1.body);
resMock.emit('end');
});
resMock.statusCode = data_1.statusCode;
resMock.headers = data_1.headers;
resMock.statusMessage = data_1.statusMessage;
_this.addExtraFieldsToRes(resMock, data_1);
// TODO: there is some error here:
// Cannot read property 'aborted' of undefined TypeError: Cannot read property 'aborted' of undefined
// however everything goes forward normally
callback(resMock);
originalCallback(resMock_1);
};
return httpMock_1.mockRequest(null, wrappedCallback);
if (!originalCallback) {
return httpMock.request.call(this, resMock_1, function () { });
}
return httpMock.request.call(this, options, wrappedCallback);
}

@@ -116,3 +141,3 @@ else {

};
_this.getExtraFieldsFromRes(res, data);
integration.getExtraFieldsFromRes(res, data);
var obj = {

@@ -123,9 +148,9 @@ data: data,

var trace = new Trace(obj);
_this.tracer.add(trace.trace());
integration.tracer.add(trace.trace());
});
if (callback) {
callback(res);
if (originalCallback) {
originalCallback(res);
}
};
return request.call(_this, options, wrappedCallback);
return request.call(this, options, wrappedCallback);
}

@@ -135,3 +160,3 @@ }

logger.error(error, integration.namespace);
return request.apply(_this, [options, callback]);
return request.apply(this, arguments);
}

@@ -151,2 +176,10 @@ };

};
HttpIntegration.prototype.wrapGot = function () {
var integration = this;
return function (request) {
return function () {
console.log("CALLED");
};
};
};
return HttpIntegration;

@@ -153,0 +186,0 @@ }(integrations_1.Integrations));

@@ -7,4 +7,6 @@ "use strict";

}
HttpMock.prototype.mockRequest = function (_, callback) {
callback();
HttpMock.prototype.request = function (resmock, callback) {
process.nextTick(function () {
callback();
});
return {

@@ -91,2 +93,7 @@ aborted: false,

once: function (event, listener) {
if (event === 'response') {
// @ts-ignore
return listener(resmock);
}
// @ts-ignore
return undefined;

@@ -140,3 +147,3 @@ },

// @ts-ignore
on: function () {
on: function (type) {
},

@@ -147,3 +154,3 @@ end: function () {

};
HttpMock.prototype.responseMockObject = function () {
HttpMock.prototype.response = function () {
var _a;

@@ -281,4 +288,4 @@ return _a = {

};
HttpMock.prototype.createResponseMock = function (emitter) {
var res = this.responseMockObject();
HttpMock.prototype.createResponse = function (emitter) {
var res = this.response();
var resMock = {};

@@ -285,0 +292,0 @@ Object.keys(res).forEach(function (key) {

{
"name": "rbi-nodejs-agent",
"version": "1.0.2",
"version": "1.0.3",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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