How to use the shimmer.wrap 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 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 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 tjmehta / primus-graphql / test / relay-network-layer.unit.js View on Github external
onCompleted: sinon.stub(),
          onError: sinon.stub(),
          onNext: sinon.stub(),
          getQueryString: sinon.stub().returns(this.query),
          getVariables: sinon.stub().returns(this.variables)
        }
        this.observable = new StaticObservable()
        shimmer.wrap(Observable.prototype, 'backoff', function (orig) {
          return function () {
            var ret = orig.apply(this, arguments)
            self.backoffObservable = ret
            sinon.spy(self.backoffObservable, 'subscribe')
            return ret
          }
        })
        shimmer.wrap(Function.prototype, 'bind', function (orig) {
          return function () {
            var bound = orig.apply(this, arguments)
            bound.__bound = this
            return bound
          }
        })
      })
      afterEach(function () {
github instana / nodejs-sensor / packages / core / src / tracing / instrumentation / protocols / graphql.js View on Github external
function instrumentExecute(executeModule) {
  shimmer.wrap(executeModule, 'execute', shimExecuteFunction.bind(null));
}
github instana / nodejs-sensor / packages / core / src / tracing / instrumentation / messaging / natsStreaming.js View on Github external
return function() {
    var subscription = originalFunction.apply(this, arguments);
    if (subscription) {
      shimmer.wrap(subscription, 'emit', shimSubscriptionEmit.bind(null, natsUrl, arguments[0]));
    }
    return subscription;
  };
}
github honeycombio / beeline-nodejs / lib / instrumentation / pg.js View on Github external
let instrumentPg = function(pg, opts = {}) {
  shimmer.wrap(pg.Client.prototype, "query", function(query) {
    return function(...args) {
      if (args.length < 1) {
        return query.apply(this, args);
      }
      if (!api.traceActive()) {
        return query.apply(this, args);
      }

      return api.startAsyncSpan(
        {
          [schema.EVENT_TYPE]: "pg",
          [schema.PACKAGE_VERSION]: opts.packageVersion,
          [schema.TRACE_SPAN_NAME]: "query",
          "db.query": getQueryString(args),
          "db.query_args": getQueryArgs(args),
          "db.query_name": getQueryName(args),
github googleapis / cloud-trace-nodejs / src / plugins / plugin-http.ts View on Github external
function patchHttps(https: HttpsModule, api: Tracer) {
  shimmer.wrap(https, 'request', request => {
    return makeRequestTrace('https:', request, api);
  });
  shimmer.wrap(https, 'get', function getWrap(): typeof httpsModule.get {
    return function getTrace(this: never) {
      const req = https.request.apply(this, arguments);
      req.end();
      return req;
    };
  });
}
github instana / nodejs-sensor / packages / core / src / tracing / instrumentation / database / mssql.js View on Github external
function instrumentRequest(Request) {
  shimmer.wrap(Request.prototype, 'query', shimMethod.bind(null, instrumentedRequestMethod));
  shimmer.wrap(Request.prototype, 'execute', shimMethod.bind(null, instrumentedRequestMethod));
  shimmer.wrap(Request.prototype, 'batch', shimMethod.bind(null, instrumentedRequestMethod));
  shimmer.wrap(Request.prototype, 'bulk', shimMethod.bind(null, instrumentedBulk));
}

shimmer

Safe(r) monkeypatching for JavaScript.

BSD-2-Clause
Latest version published 6 years ago

Package Health Score

67 / 100
Full package analysis