def start_transaction(
      name = nil,
      type = nil,
      context: nil,
      trace_context: nil
    )
      return nil unless config.instrument?

      if (transaction = current_transaction)
        raise ExistingTransactionError,
          "Transactions may not be nested.\nAlready inside #{transaction}"
      end

      sampled = trace_context ? trace_context.recorded? : random_sample?

      transaction =
        Transaction.new(
          name,
          type,
          context: context,
          trace_context: trace_context,
          sampled: sampled,
          tags: config.default_tags
        )

      transaction.start

      self.current_transaction = transaction
    end
def start_transaction(
      name = nil,
      type = nil,
      context: nil,
      trace_context: nil
    )
      return nil unless config.instrument?

      if (transaction = current_transaction)
        raise ExistingTransactionError,
          "Transactions may not be nested.\nAlready inside #{transaction}"
      end

      sampled = trace_context ? trace_context.recorded? : random_sample?

      transaction =
        Transaction.new(
          name,
          type,
          context: context,
          trace_context: trace_context,
          sampled: sampled,
          tags: config.default_tags
        )

      transaction.start

      self.current_transaction = transaction
    end
rubocop:disable Metrics/MethodLength