Skip to content

Conversation

alexbozhenko
Copy link
Member

@alexbozhenko alexbozhenko commented Jun 30, 2025

This was claude code generated/human verified,
based on #911
and #334 (comment)
And similar to debug option in nats.js

We can copy-paste the tracing snippet that @kozlovic shows in the second link(I found it extremely useful), but why don't we make it part of the client, so it is easy to do just:

nc, err := nats.Connect(nats.DefaultURL, nats.WithProtocolTrace(nats.NewStderrTrace()))

and easily see all the nitty-gritty details from the wire
image
in any program or test

func (tc *tracedConn) Read(b []byte) (n int, err error) {
n, err = tc.Conn.Read(b)
if err == nil && tc.trace != nil && tc.trace.DataReceived != nil {
// Make a copy of the data to avoid race conditions
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if this copying is actually needed

func (tc *tracedConn) Write(b []byte) (n int, err error) {
n, err = tc.Conn.Write(b)
if err == nil && tc.trace != nil && tc.trace.DataSent != nil {
// Make a copy of the data to avoid race conditions
Copy link
Member Author

Choose a reason for hiding this comment

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

Same. Not sure if we need to copy.

@alexbozhenko alexbozhenko changed the title Add protocol trace [Added] option WithConnTrace to enable protocol tracing Jun 30, 2025
@alexbozhenko alexbozhenko changed the title [Added] option WithConnTrace to enable protocol tracing [Added] option WithProtocolTrace to enable protocol tracing Jul 1, 2025
@coveralls
Copy link

Coverage Status

coverage: 84.638% (-0.1%) from 84.738%
when pulling 189c566 on alexbozhenko:protocol_trace
into ccb20c2 on nats-io:main.

@alexbozhenko alexbozhenko marked this pull request as ready for review July 1, 2025 21:57
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.

2 participants