<commit_before>require('TraceKit')
var logger = require('./lib/logger')

var defaultOptions = {
  apiHost: 'https://opbeat.com',
  logger: 'javascript',
}

function Opbeat () {
  this.VERSION = '0.0.1'

  this.isInstalled = false
  this.options = defaultOptions

  this.isPlatformSupport = function () {
    // TODO: Add some platform checks
    return true
  }

  this.onTraceKitReport = function (stackInfo, options) {
    logger.log('onTraceKitReport', stackInfo, options)
  }

}

/*
 * Configure Opbeat with Opbeat.com credentials and other options
 *
 * @param {object} options Optional set of of global options
 * @return {Opbeat}
 */

Opbeat.prototype.config = function (options) {
  return this
}

/*
 * Installs a global window.onerror error handler
 * to capture and report uncaught exceptions.
 * At this point, install() is required to be called due
 * to the way TraceKit is set up.
 *
 * @return {Opbeat}
 */

Opbeat.prototype.install = function () {
  if (this.isPlatformSupport() && !this.isInstalled) {
    TraceKit.report.subscribe(this.onTraceKitReport)
    this.isInstalled = true
  }

  return this

}

/*
 * Uninstalls the global error handler.
 *
 * @return {Opbeat}
 */
Opbeat.prototype.uninstall = function () {
  TraceKit.report.uninstall()
  this.isInstalled = false

  return this
}

/*
 * Manually capture an exception and send it over to Opbeat.com
 *
 * @param {error} ex An exception to be logged
 * @param {object} options A specific set of options for this error [optional]
 * @return {Opbeat}
 */
Opbeat.prototype.captureException = function (ex, options) {
  return this
}

/*
 * Set/clear a user to be sent along with the payload.
 *
 * @param {object} user An object representing user data [optional]
 * @return {Opbeat}
 */
Opbeat.prototype.setUserContext = function (user) {
  return this
}

/*
 * Set extra attributes to be sent along with the payload.
 *<commit_msg>Add implementation of captureException<commit_after>require('TraceKit')
var logger = require('./lib/logger')

var defaultOptions = {
  apiHost: 'https://opbeat.com',
  logger: 'javascript',
}

function Opbeat () {
  this.VERSION = '0.0.1'

  this.isInstalled = false
  this.options = defaultOptions

  this.isPlatformSupport = function () {
    // TODO: Add some platform checks
    return true
  }

  this.onTraceKitReport = function (stackInfo, options) {
    logger.log('onTraceKitReport', stackInfo, options)
  }

}

/*
 * Configure Opbeat with Opbeat.com credentials and other options
 *
 * @param {object} options Optional set of of global options
 * @return {Opbeat}
 */

Opbeat.prototype.config = function (options) {
  return this
}

/*
 * Installs a global window.onerror error handler
 * to capture and report uncaught exceptions.
 * At this point, install() is required to be called due
 * to the way TraceKit is set up.
 *
 * @return {Opbeat}
 */

Opbeat.prototype.install = function () {
  if (this.isPlatformSupport() && !this.isInstalled) {
    TraceKit.report.subscribe(this.onTraceKitReport)
    this.isInstalled = true
  }

  return this

}

/*
 * Uninstalls the global error handler.
 *
 * @return {Opbeat}
 */
Opbeat.prototype.uninstall = function () {
  TraceKit.report.uninstall()
  this.isInstalled = false

  return this
}

/*
 * Manually capture an exception and send it over to Opbeat.com
 *
 * @param {error} ex An exception to be logged
 * @param {object} options A specific set of options for this error [optional]
 * @return {Opbeat}
 */
Opbeat.prototype.captureException = function (ex, options) {
  if (!(ex instanceof Error)) {
    throw 'Passed exception needs to be an instanceof Error'
  }

  // TraceKit.report will re-raise any exception passed to it,
  // which means you have to wrap it in try/catch. Instead, we
  // can wrap it here and only re-raise if TraceKit.report
  // raises an exception different from the one we asked to
  // report on.

  try {
    TraceKit.report(ex, options)
  } catch(ex1) {
    if (ex !== ex1) {
      throw ex1
    }
  }

  return this
}

/*
 * Set/clear a user to be sent along with the payload.
 *
 * @param {object} user An object representing user data [optional]
 * @return {Opbeat}
 */
Opbeat.prototype.setUserContext = function (user) {
  return this
}

/*
 * Set extra attributes to be sent along with the payload.
 *
{'fraction_non_alphanumeric': 0.1107242339832869, 'fraction_numerical': 0.0020891364902506965, 'mean_word_length': 3.401430030643514, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '5235378', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1304, 'n_words': 439}