<commit_before>'use strict'

var semver = require('semver')
var debug = require('debug')('opbeat')
var shimmer = require('../shimmer')

module.exports = function (generic, opbeat, version) {
  if (!semver.satisfies(version, '^2.0.0')) {
    debug('generic-pool version %s not suppoted - aborting...', version)
    return generic
  }

  debug('shimming generic-pool.Pool')
  shimmer.wrap(generic, 'Pool', function (orig) {
    return function wrappedPool () {
      var trans = opbeat._instrumentation.currentTransaction
      var uuid = trans && trans._uuid
      debug('intercepted call to generic-pool.Pool %o', { uuid: uuid })

      var pool
      if (this instanceof generic.Pool) {
        var args = [].slice.call(arguments)
        args.unshift(null)
        pool = new (Function.prototype.bind.apply(orig, args))()
      } else {
        pool = orig.apply(this, arguments)
      }

      shimmer.wrap(pool, 'acquire', function (orig) {
        return function wrappedAcquire () {
          var trans = opbeat._instrumentation.currentTransaction
          var uuid = trans && trans._uuid
          debug('intercepted call to pool.acquire %o', { uuid: uuid })

          var args = arguments
          var cb = args[0]
          if (typeof cb === 'function') {
            args[0] = opbeat._instrumentation.bindFunction(cb)
          }

          return orig.apply(this, args)
        }<commit_msg>generic-pool: clean up pool.acquire patch<commit_after>'use strict'

var semver = require('semver')
var debug = require('debug')('opbeat')
var shimmer = require('../shimmer')

module.exports = function (generic, opbeat, version) {
  if (!semver.satisfies(version, '^2.0.0')) {
    debug('generic-pool version %s not suppoted - aborting...', version)
    return generic
  }

  debug('shimming generic-pool.Pool')
  shimmer.wrap(generic, 'Pool', function (orig) {
    return function wrappedPool () {
      var trans = opbeat._instrumentation.currentTransaction
      var uuid = trans && trans._uuid
      debug('intercepted call to generic-pool.Pool %o', { uuid: uuid })

      var pool
      if (this instanceof generic.Pool) {
        var args = [].slice.call(arguments)
        args.unshift(null)
        pool = new (Function.prototype.bind.apply(orig, args))()
      } else {
        pool = orig.apply(this, arguments)
      }

      shimmer.wrap(pool, 'acquire', function (orig) {
        return function wrappedAcquire () {
          var trans = opbeat._instrumentation.currentTransaction
          var uuid = trans && trans._uuid
          debug('intercepted call to pool.acquire %o', { uuid: uuid })

          var cb = arguments[0]
          if (typeof cb === 'function') {
            arguments[0] = opbeat._instrumentation.bindFunction(cb)
          }

          return orig.apply(this, arguments)
        }
{'fraction_non_alphanumeric': 0.12969525159461376, 'fraction_numerical': 0.003543586109142452, 'mean_word_length': 2.6238767650834403, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4544285', 'n_tokens_mistral': 823, 'n_tokens_neox': 821, 'n_words': 211}