How to use the shimmer.massWrap function in shimmer

To help you get started, we’ve selected a few shimmer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github open-telemetry / opentelemetry-js / packages / opentelemetry-plugin-mongodb-core / src / mongodb.ts View on Github external
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;
  }
github census-instrumentation / opencensus-node / packages / opencensus-instrumentation-grpc / src / grpc.ts View on Github external
return function makeClientConstructor(
        this: typeof grpcTypes.Client,
        methods: grpcTypes.ServiceDefinition,
        serviceName: string,
        options: grpcTypes.GenericClientOptions
      ) {
        const client = original.apply(this, arguments);
        shimmer.massWrap(
          client.prototype,
          Object.keys(methods) as never[],
          plugin.getPatchedClientMethods()
        );
        return client;
      };
    };
github tubackkhoa / tkframework / server / data / loader / sequelize.js View on Github external
function shimModel(target) {
  if (target.findById.__wrapped) return

  shimmer.massWrap(target, ['findById', 'findByPrimary'], original => {
    return function batchedFindById(id, options = {}) {
      if ([null, undefined].indexOf(id) !== -1) {
        return Promise.resolve(null)
      }
      if (options.transaction) {
        return original.apply(this, arguments)
      }
      return loaderForModel(this, this.primaryKeyAttribute, this.primaryKeyField, options)
        .load(id).then(rejectOnEmpty.bind(null, options))
    }
  })
}
github census-instrumentation / opencensus-node / packages / opencensus-instrumentation-mongodb / src / mongodb.ts View on Github external
protected applyPatch() {
    this.logger.debug('Patched MongoDB');

    if (this.moduleExports.Server) {
      this.logger.debug('patching mongodb-core.Server.prototype.command');
      shimmer.wrap(
        this.moduleExports.Server.prototype,
        'command' as never,
        this.getPatchCommand()
      );
      this.logger.debug(
        'patching mongodb-core.Server.prototype functions:',
        this.SERVER_FNS
      );
      shimmer.massWrap(
        [this.moduleExports.Server.prototype],
        this.SERVER_FNS as never[],
        this.getPatchQuery()
      );
    }

    if (this.moduleExports.Cursor) {
      this.logger.debug(
        'patching mongodb-core.Cursor.prototype functions:',
        this.CURSOR_FNS_FIRST
      );
      shimmer.massWrap(
        [this.moduleExports.Cursor.prototype],
        this.CURSOR_FNS_FIRST as never[],
        this.getPatchCursor()
      );
github mickhansen / dataloader-sequelize / src / index.js View on Github external
function shimModel(target) {
  if (target.findByPk ? target.findByPk.__wrapped : target.findById.__wrapped) return;

  shimmer.massWrap(target, methods(Sequelize.version).findByPk, original => {
    return function batchedFindById(id, options = {}) {
      if ([null, undefined].indexOf(id) !== -1) {
        return Promise.resolve(null);
      }
      if (options.transaction || options.include || activeClsTransaction() || !options[EXPECTED_OPTIONS_KEY]) {
        return original.apply(this, arguments);
      }

      const loaders = options[EXPECTED_OPTIONS_KEY].loaders;
      let loader = loaders[this.name].byPrimaryKey;
      if (options.raw) {
        const cacheKey = getCacheKey(this, this.primaryKeyAttribute, {raw: options.raw});
        loader = loaders.autogenerated.get(cacheKey);
        if (!loader) {
          loader = createModelAttributeLoader(this, this.primaryKeyAttribute, {raw: options.raw, logging: options.logging});
          loaders.autogenerated.set(cacheKey, loader);
github honeycombio / beeline-nodejs / lib / instrumentation / mysql2.js View on Github external
let instrumentMysql2 = function(mysql2, opts = {}) {
  shimmer.massWrap(mysql2.Connection.prototype, ["execute", "query"], function(original) {
    return function(...args) {
      if (args.length < 1 || !api.traceActive()) {
        return original.apply(this, args);
      }

      let query = args[0].sql;
      if (typeof query === "undefined") {
        query = args[0];
      }
      return api.startAsyncSpan(
        {
          [schema.EVENT_TYPE]: "mysql2",
          [schema.PACKAGE_VERSION]: opts.packageVersion,
          [schema.TRACE_SPAN_NAME]: "query",
          "db.query": query,
        },
github iopipe / iopipe-js-trace / src / plugins / mongodb.js View on Github external
}

  if (!clientTarget.__iopipeShimmer) {
    shimmer.massWrap(clientTarget, clientOps, wrapCommand);
    clientTarget.__iopipeShimmer = true;
  }
  if (!collectionTarget.__iopipeShimmer) {
    shimmer.massWrap(collectionTarget, collectionOps, wrapCommand);
    collectionTarget.__iopipeShimmer = true;
  }
  if (!serverTarget.__iopipeShimmer) {
    shimmer.massWrap(serverTarget, serverOps, wrapCommand);
    serverTarget.__iopipeShimmer = true;
  }
  if (!cursorTarget.__iopipeShimmer) {
    shimmer.massWrap(cursorTarget, cursorOps, wrapCommand);
    cursorTarget.__iopipeShimmer = true;
  }

  return true;

  function wrapCommand(original, command) {
    if (typeof original !== 'function') {
      return original;
    }
    return function wrappedCommand() {
      const context = this;
      const id = createId();
      const args = Array.prototype.slice.call(arguments);
      let cb, cbIdx, wrappedCb;

      for (const i in args) {

shimmer

Safe(r) monkeypatching for JavaScript.

BSD-2-Clause
Latest version published 5 years ago

Package Health Score

67 / 100
Full package analysis