export function compressTransaction()

in packages/rum-core/src/common/compress.js [199:263]


export function compressTransaction(transaction) {
  const spans = transaction.spans.map(span => {
    const spanData = {
      id: span.id,
      n: span.name,
      t: span.type,
      s: span.start,
      d: span.duration,
      c: compressContext(span.context),
      o: span.outcome,
      sr: span.sample_rate
    }
    /**
     * Set parentId only for spans that are child of other spans
     * and not transaction as it will be inferred
     */
    if (span.parent_id !== transaction.id) {
      spanData.pid = span.parent_id
    }
    /**
     * Set the below fields only when they are truthy or exists
     */
    if (span.sync === true) {
      spanData.sy = true
    }
    if (span.subtype) {
      spanData.su = span.subtype
    }
    if (span.action) {
      spanData.ac = span.action
    }
    return spanData
  })

  const tr = {
    id: transaction.id,
    pid: transaction.parent_id,
    tid: transaction.trace_id,
    n: transaction.name,
    t: transaction.type,
    d: transaction.duration,
    c: compressContext(transaction.context),
    k: compressMarks(transaction.marks),
    me: compressMetricsets(transaction.breakdown),
    y: spans,
    yc: {
      sd: spans.length
    },
    sm: transaction.sampled,
    sr: transaction.sample_rate,
    o: transaction.outcome
  }

  if (transaction.experience) {
    let { cls, fid, tbt, longtask } = transaction.experience
    tr.exp = { cls, fid, tbt, lt: longtask }
  }

  if (transaction.session) {
    const { id, sequence } = transaction.session
    tr.ses = { id, seq: sequence }
  }

  return tr
}