Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
init() {
// using shimmer directly cause can only be bundled in node
shimmer.wrap(http, 'get', () => httpGetWrapper(http));
shimmer.wrap(http, 'request', httpWrapper);
shimmer.wrap(https, 'get', () => httpGetWrapper(https));
shimmer.wrap(https, 'request', httpWrapper);
moduleUtils.patchModule(
'wreck',
'request',
WreckWrapper
);
},
};
export function removeContext(sequelize) {
const Model = /^[45]/.test(sequelize.constructor.version) ? // v3 vs v4
sequelize.constructor.Model : sequelize.constructor.Model.prototype;
shimmer.massUnwrap(Model, methods(Sequelize.version).findByPk);
shimmer.unwrap(sequelize.constructor.Association.BelongsTo.prototype, 'get');
shimmer.unwrap(sequelize.constructor.Association.HasOne.prototype, 'get');
shimmer.unwrap(sequelize.constructor.Association.HasMany.prototype, 'get');
shimmer.unwrap(sequelize.constructor.Association.BelongsToMany.prototype, 'get');
}
return function register(
// tslint:disable-next-line:no-any
this: grpcTypes.Server & { handlers: any },
name: string,
handler: grpcTypes.handleCall,
serialize: grpcTypes.serialize,
deserialize: grpcTypes.deserialize,
type: string
) {
const result = originalRegister.apply(this, arguments);
const handlerSet = this.handlers[name];
// Patch the methods that are invoked when a gRPC service call is
// made. The function 'func' is the user-implemented handling function.
shimmer.wrap(
handlerSet,
'func',
(originalFunc: grpcTypes.handleCall) => {
return function func(
this: typeof handlerSet,
call: ServerCallWithMeta,
callback: SendUnaryDataCallback
) {
const self = this;
const traceOptions: TraceOptions = {
name: `grpc.${name.replace('/', '')}`,
kind: SpanKind.SERVER,
};
const spanContext = GrpcPlugin.getSpanContext(call.metadata);
function instrumentPool(Pool) {
shimmer.wrap(Pool, 'query', shimQuery);
// There is also an 'execute' method on the pool object but it uses the connection internally, so we do not need to
// instrument it. This is handled by the instrumented methods on Connection. We do need to instrument 'pool.query',
// though.
shimmer.wrap(Pool, 'getConnection', shimGetConnection);
}
let filenames = []
files.forEach(filePattern => {
if (filePattern) {
filenames = filenames.concat(glob.sync(filePattern, opt))
}
})
exclude_files.forEach(filePattern => {
if (filePattern) {
_.pullAll(filenames, glob.sync(filePattern, opt))
}
})
filenames = _.uniq(filenames)
debug('matched files: %j', filenames)
// wrap Module.prototype._compile
shimmer.wrap(Module.prototype, '_compile', function (__compile) {
return function koaBreakpointCompile (content, filename) {
if (!_.includes(filenames, filename)) {
try {
return __compile.call(this, content, filename)
} catch (e) {
// `try { require('...') } catch (e) { ... }` will not print compile error message
debug('cannot compile file: %s', filename)
debug(e.stack)
throw e
}
}
let parsedCodes
try {
parsedCodes = esprima.parse(content, { loc: true })
} catch (e) {
protected applyUnpatch(): void {
// Only Client and Server constructors will be unwrapped. Any existing
// Client or Server instances will still trace
shimmer.unwrap(this.moduleExports, 'createServer');
shimmer.unwrap(this.moduleExports, 'createSecureServer');
shimmer.unwrap(this.moduleExports, 'connect');
}
this._moduleExports.Server.prototype,
// Forced to ignore due to incomplete typings
// tslint:disable-next-line:ban-ts-ignore
// @ts-ignore
fn,
this._getPatchCommand(fn)
);
}
}
if (this._moduleExports.Cursor) {
this._logger.debug(
'patching mongodb-core.Cursor.prototype functions:',
this._CURSOR_METHODS
);
shimmer.massWrap(
[this._moduleExports.Cursor.prototype],
this._CURSOR_METHODS as never[],
// tslint:disable-next-line:no-any
this._getPatchCursor() as any
);
}
return this._moduleExports;
}
function unwrap() {
if (serverTarget.__iopipeShimmer) {
shimmer.massUnwrap(serverTarget, serverOps);
delete serverTarget.__iopipeShimmer;
}
if (collectionTarget.__iopipeShimmer) {
shimmer.massUnwrap(collectionTarget, collectionOps);
delete collectionTarget.__iopipeShimmer;
}
if (cursorTarget.__iopipeShimmer) {
shimmer.massUnwrap(cursorTarget, cursorOps);
delete cursorTarget.__iopipeShimmer;
}
if (clientTarget.__iopipeShimmer) {
shimmer.massUnwrap(clientTarget, clientOps); // mass just seems to hang and not complete
delete clientTarget.__iopipeShimmer;
}
}
function unwrap() {
if (serverTarget.__iopipeShimmer) {
shimmer.massUnwrap(serverTarget, serverOps);
delete serverTarget.__iopipeShimmer;
}
if (collectionTarget.__iopipeShimmer) {
shimmer.massUnwrap(collectionTarget, collectionOps);
delete collectionTarget.__iopipeShimmer;
}
if (cursorTarget.__iopipeShimmer) {
shimmer.massUnwrap(cursorTarget, cursorOps);
delete cursorTarget.__iopipeShimmer;
}
if (clientTarget.__iopipeShimmer) {
shimmer.massUnwrap(clientTarget, clientOps); // mass just seems to hang and not complete
delete clientTarget.__iopipeShimmer;
}
}
function unwrap() {
if (serverTarget.__iopipeShimmer) {
shimmer.massUnwrap(serverTarget, serverOps);
delete serverTarget.__iopipeShimmer;
}
if (collectionTarget.__iopipeShimmer) {
shimmer.massUnwrap(collectionTarget, collectionOps);
delete collectionTarget.__iopipeShimmer;
}
if (cursorTarget.__iopipeShimmer) {
shimmer.massUnwrap(cursorTarget, cursorOps);
delete cursorTarget.__iopipeShimmer;
}
if (clientTarget.__iopipeShimmer) {
shimmer.massUnwrap(clientTarget, clientOps); // mass just seems to hang and not complete
delete clientTarget.__iopipeShimmer;
}
}