Skip to content

Allow consuming trace events programmatically#400

Merged
bbatsov merged 1 commit into
masterfrom
trace-event-listeners
Jun 22, 2026
Merged

Allow consuming trace events programmatically#400
bbatsov merged 1 commit into
masterfrom
trace-event-listeners

Conversation

@bbatsov

@bbatsov bbatsov commented Jun 22, 2026

Copy link
Copy Markdown
Member

First step of giving CIDER a dedicated trace buffer (clojure-emacs/cider, Tier 2 of the enlighten/tracing audit).

Tracing only ever printed a formatted call tree to *out*, which is hard to build a UI on. This adds a listener registry so trace events can be consumed programmatically:

  • add-trace-listener/remove-trace-listener - register a fn that gets a structured event per call and per return. Events are paired by :id and carry :name, :depth, and :args (on :call) or :value (on :return).
  • set-output-mode! - choose whether output goes to the REPL (:repl, the default), to listeners (:listeners), or :both.

The REPL path is unchanged and remains the default, so existing tracing behaves exactly as before. Event args are bounded the same way the printed path already bounds them, so tracing a fn called with a lazy/infinite arglist (e.g. (apply f (range))) can't blow up the heap.

cider-nrepl will register a listener and stream these events to a *cider-trace* buffer once this is released.

Tracing only ever printed a formatted call tree to *out*, which made it
hard to build anything on top of (an editor trace buffer, say). Add a
listener registry: add-trace-listener registers a fn that receives a
structured event per call and per return (paired by :id, carrying :name,
:depth, :args/:value), and set-output-mode! chooses whether output goes
to the REPL, to listeners, or both. The REPL path is unchanged and stays
the default.

Args are bounded the same way the printed path is, so tracing a fn called
with a lazy or infinite arglist (e.g. (apply f (range))) can't OOM.
@bbatsov bbatsov merged commit deff425 into master Jun 22, 2026
12 checks passed
@alexander-yakushev alexander-yakushev deleted the trace-event-listeners branch July 4, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant