How to use shimmer - 10 common examples

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 epsagon / epsagon-node / src / events / http.js View on Github external
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
        );
    },
};
github mickhansen / dataloader-sequelize / src / index.js View on Github external
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');
}
github census-instrumentation / opencensus-node / packages / opencensus-instrumentation-grpc / src / grpc.ts View on Github external
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);
github instana / nodejs-sensor / packages / core / src / tracing / instrumentation / database / mysql.js View on Github external
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);
}
github nswbmw / koa-await-breakpoint / index.js View on Github external
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) {
github census-instrumentation / opencensus-node / packages / opencensus-instrumentation-http2 / src / http2.ts View on Github external
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');
  }
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 iopipe / iopipe-js-trace / src / plugins / mongodb.js View on Github external
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;
  }
}
github iopipe / iopipe-js-trace / src / plugins / mongodb.js View on Github external
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;
  }
}
github iopipe / iopipe-js-trace / src / plugins / mongodb.js View on Github external
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;
  }
}

shimmer

Safe(r) monkeypatching for JavaScript.

BSD-2-Clause
Latest version published 6 years ago

Package Health Score

67 / 100
Full package analysis