function createSegment({ id, name, recorder, parent, transaction }) {
  if (!parent || !transaction?.isActive()) {
    logger.trace(
      {
        hasParent: !!parent,
        transactionActive: transaction?.isActive()
      },
      'Not creating segment %s, no parent or active transaction available.',
      name
    )
    return null
  }

  if (parent.opaque) {
    logger.trace('Skipping child addition on opaque segment')
    return parent
  }

  logger.trace('Adding segment %s to %s in %s', name, parent.name, transaction.id)

  let collect = true

  if (transaction.numSegments >= this.agent.config.max_trace_segments) {
    collect = false
  }
  transaction.incrementCounters()

  const segment = new TraceSegment({
    id,
    config: this.agent.config,
    name,
    collect,
    root: transaction.trace.root,
    parentId: parent.id
  })

  if (recorder) {
    transaction.addRecorder(recorder.bind(null, segment))
  }

  if (collect) {
    transaction.trace.segments.add(segment)
  }

  return segment
}
Create segment and assign recorder to transaction. This also increments counters of
segments.
Does not create segment if there is no parent, transaction is active or parent
is opaque.

@param {object} params to fn
@param {string} params.id if present, it will use id as segment.id. only used in otel bridge mode.
@param {string} params.name name of segment
@param {function} params.recorder time slice metrics recorder for segment
@param {TraceSegment} params.parent parent segment of segment being created
@param {Transaction} params.transaction active transaction
@returns {TraceSegment|null} returns new segment, existing parent if opaque or null(no parent or transaction inactive)