Skip to content

qlog,quiche,tokio-quiche: add QlogSink abstraction for custom qlogs#2500

Open
strtok wants to merge 1 commit into
cloudflare:masterfrom
strtok:ebremen/qlog
Open

qlog,quiche,tokio-quiche: add QlogSink abstraction for custom qlogs#2500
strtok wants to merge 1 commit into
cloudflare:masterfrom
strtok:ebremen/qlog

Conversation

@strtok

@strtok strtok commented May 29, 2026

Copy link
Copy Markdown

Add a QlogSink trait that allows overriding qlog behavior. Previously QlogStreamer was instantiated with a writer object. Instead, it is instantiated with a QlogSink object which allows more flexibility. A QlogWriterSink implementation provides backwards compatibility.

Implementations have new methods for overriding qlog behavior:

  • Connection::set_qlog_sink and set_qlog_sink_with_level allow setting a custom qlog sink. The existing set_qlog and set_qlog_with_level exist for backwards compatibility and call these new functions with a QlogWriterSink object.
  • A new ConnectionHook::create_qlog_sink hook can be implemented to install a sink at connection accept/connect time. If a sink is returned it overrides any qlog_dir behavior.

Add QlogStreamer::should_log(EventType) that allows high volume events to be skipped without construction. Modified both the recv and write path to make use of this.

@strtok strtok requested a review from a team as a code owner May 29, 2026 19:36

@meha23 meha23 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strtok:ebremen/qlog

@gregor-cf gregor-cf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. I did a quick pass and had some minor comments and nits.

Comment thread qlog/src/sink.rs
fn add_event(&mut self, event: events::Event) -> Result<()>;

/// Add a pretty-printed native qlog event to the stream.
fn add_event_pretty(&mut self, event: events::Event) -> Result<()> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the `pretty functions. The sink might not actually have a serialization or similar that can do pretty printing. IMHO if pretty printing is desired, then we that should be handled by the sink / writer internally, but it shouldn't be exposed to callers of QlogSink.

But I'll let the folks who orginally added the QlogStreamer chime in.

Comment thread qlog/src/sink.rs Outdated
Comment thread qlog/src/sink.rs Outdated
Comment thread qlog/src/streamer.rs
/// Writes a serializable to a pretty-printed JSON-SEQ record using
/// [std::time::Instant::now()].
pub fn add_event_now_pretty<E: Serialize + Eventable>(
pub fn add_event_now_pretty<E: Into<crate::QlogEvent> + Eventable>(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd remove the _pretty functions here too....

Comment thread qlog/src/sink.rs
Comment thread qlog/src/streamer.rs Outdated
Comment thread qlog/src/streamer.rs Outdated
Comment thread quiche/src/lib.rs
Comment thread quiche/src/lib.rs
…iting

Add a QlogSink trait that allows overriding qlog behavior. Previously
QlogStreamer was instantiated with a writer object. Instead, it is
instantiated with a QlogSink object which allows more flexibility. A
QlogWriterSink implementation provides backwards compatibility.

Implementations have new methods for overriding qlog behavior:
  - Connection::set_qlog_sink and set_qlog_sink_with_level allow setting
    a custom qlog sink. The existing set_qlog and set_qlog_with_level
    exist for backwards compatibility and call these new functions with
    a QlogWriterSink object.
  - A new ConnectionHook::create_qlog_sink hook can be implemented to
    install a sink at connection accept/connect time. If a sink is
    returned it overrides any qlog_dir behavior.

Add QlogStreamer::should_log(EventType) that allows high volume events
to be skipped without construction. Modified both the recv and write
path to make use of this.

Remove QlogStreamer::writer. A QlogStreamer is no longer guaranteed to
be backed by a Writer. The underlying QlogSink is exposed via
QlogStreamer::sink(), where it's used by tests to access the underlying
test sink.
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.

4 participants