<commit_before>var Promise = require('es6-promise').Promise
var logger = require('../lib/logger')
var frames = require('../exceptions/frames')
var traceCache = require('./traceCache')

var Trace = module.exports = function (transaction, signature, type, options) {
  this.transaction = transaction
  this.signature = signature
  this.type = type
  this.ended = false
  this._parent = null

  // Start timers
  this._start = window.performance.now()
  this._startStamp = new Date()

  this._isFinish = new Promise(function (resolve, reject) {
    this._markFinishedFunc = resolve
  }.bind(this))

  if(options.config.get('performance.enableStackFrames')) {
    this.getTraceStackFrames(function (frames) {
      if (frames) {
        this.frames = frames.reverse() // Reverse frames to make Opbeat happy
      }
      this._markFinishedFunc() // Mark the trace as finished
    }.bind(this))
  } else {
    this._markFinishedFunc() // Mark the trace as finished
  }<commit_msg>Only generate stack frames 10% of the time (for now)<commit_after>var Promise = require('es6-promise').Promise
var logger = require('../lib/logger')
var frames = require('../exceptions/frames')
var traceCache = require('./traceCache')
var utils = require('../lib/utils')

var Trace = module.exports = function (transaction, signature, type, options) {
  this.transaction = transaction
  this.signature = signature
  this.type = type
  this.ended = false
  this._parent = null

  // Start timers
  this._start = window.performance.now()
  this._startStamp = new Date()

  this._isFinish = new Promise(function (resolve, reject) {
    this._markFinishedFunc = resolve
  }.bind(this))

  // Only generate stack frames 10% of the time
  var shouldGenerateStackFrames = utils.getRandomInt(0, 10) === '1'

  if(options.config.get('performance.enableStackFrames')) {
    shouldGenerateStackFrames = true
  }

  if(shouldGenerateStackFrames) {
    this.getTraceStackFrames(function (frames) {
      if (frames) {
        this.frames = frames.reverse() // Reverse frames to make Opbeat happy
      }
      this._markFinishedFunc() // Mark the trace as finished
    }.bind(this))
  } else {
    this._markFinishedFunc() // Mark the trace as finished
  }
{'fraction_non_alphanumeric': 0.12533814247069433, 'fraction_numerical': 0.004508566275924256, 'mean_word_length': 3.575257731958763, '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': '2858241', 'n_tokens_mistral': 662, 'n_tokens_neox': 628, 'n_words': 172}