lib/instrumentation/protocol.js
function encode (samples, durations, cb) {
  var agent = samples.length > 0 ? samples[0]._agent : null
  var transactions = groupTransactions(samples, durations)
  var traces = [].concat.apply([], samples.map(function (trans) {
    return trans.traces
  }))
  var groups = groupTraces(traces)
  var raw = rawTransactions(samples)

  if (agent && agent.captureTraceStackTraces) {
    addStackTracesToTraceGroups(groups, traces, done)
  } else {
    process.nextTick(done)
  }

  function done () {
    cb({ // eslint-disable-line standard/no-callback-literal
      transactions: transactions,
      traces: {
        groups: groups,
        raw: raw
      }
    })
  }
}
function encode (samples, durations, cb) {
  var agent = samples.length > 0 ? samples[0]._agent : null
  var transactions = groupTransactions(samples, durations)
  var traces = [].concat.apply([], samples.map(function (trans) {
    return trans.traces
  }))
  var groups = groupTraces(traces)
  var raw = rawTransactions(samples)

  if (agent && agent.captureTraceStackTraces) {
    addStackTracesToTraceGroups(groups, traces, done)
  } else {
    process.nextTick(done)
  }

  function done () {
    cb({ // eslint-disable-line standard/no-callback-literal
      transactions: transactions,
      traces: {
        groups: groups,
        raw: raw
      }
    })
  }
}
function encode ( samples , durations , cb ) { var agent = samples . length > 0 ? samples [ 0 ] . _agent : null var transactions = groupTransactions ( samples , durations ) var traces = [ ] . concat . apply ( [ ] , samples . map ( function ( trans ) { return trans . traces } ) ) var groups = groupTraces ( traces ) var raw = rawTransactions ( samples ) if ( agent && agent . captureTraceStackTraces ) { addStackTracesToTraceGroups ( groups , traces , done ) } else { process . nextTick ( done ) } function done ( ) { cb ( { // eslint-disable-line standard/no-callback-literal transactions : transactions , traces : { groups : groups , raw : raw } } ) } }
Encodes recorded transactions into a format expected by the Opbeat intake
API.

samples:
An array containing objects of type Transaction. It's expected that each
Transaction have a unique name within a 15ms window based on its duration.

durations:
An object whos keys are generated by `transactionGroupingKey`. Each value
is an array of floats representing the duration in milliseconds of each
recorded Transaction that belongs to that key.

cb:
A callback which will be called with the encoded data.
Encodes recorded transactions into a format expected by the Opbeat intake API .