   if an exception happens before then.  An exception thrown by the
   future after that point will produce an exception from the next call
   to the InputStream read or close methods."
-  [db query entity version query-options log-id munge-fn pretty-print]
+  [db query entity version query-options munge-fn
+   {:keys [log-queries pretty-print query-id] :as context}]
   ;; Client disconnects present as generic IOExceptions from the
   ;; output writer (via stream-json), and we just log them at debug
   ;; level.  For now, after the first row, there's nothing we can do

      ;; Log origin and AST of incoming query
      (let [{:keys [origin query]} query-map]
        (log/infof "PDBQuery:%s:%s"
                   log-id (-> (sorted-map :origin origin :ast query)
                              json/generate-string))))

    (try
      (jdbc/with-transacted-connection scf-read-db
        (let [munge-fn (get-munge-fn entity version query-options url-prefix)
              {:keys [results-query count-query]} (-> remaining-query
                                                      coerce-from-json
                                                      (query->sql entity
                                                                  version
                                                                  query-options
                                                                  {:log-id log-id}))
              query-error (promise)
              resp (http/streamed-response
                    buffer


(defn preferred-produce-streaming-body
  [version query-map context]
  (let [{:keys [scf-read-db url-prefix warn-experimental pretty-print
                log-queries query-id]
         :or {warn-experimental true}} context
        query-config (select-keys context [:node-purge-ttl :add-agent-report-filter])
        {:keys [query remaining-query entity query-options]}
        (user-query->engine-query version query-map query-config warn-experimental)]
