New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support tracing JS api calls #849
Conversation
This enables CLI to trace into the JetStream context
|
Signed-off-by: R.I.Pienaar <rip@devco.net>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
TraceSent TraceOperation = 0 | ||
// TraceReceived indicate the payload is being received on subj | ||
TraceReceived TraceOperation = 1 | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative to using these types could be for example to do something similar to what httptrace package does with a struct where multiple callbacks are defined. For example with a ClientTrace struct like the following, it could be made to implement the options for JSOpt to configure just a context:
type ClientTrace struct {
RequestSent func(subj string, payload []byte, hdr Header)
ResponseReceived func(subj string, payload []byte, hdr Header)
// ProtocolSent...
// ProtocolReceived...
// Other misc low level connect options ala net/http/httptrace maybe
}
func (ct ClientTrace) configureJSContext(js *jsOpts) error {
js.ctrace = ct
js.shouldTrace = true
return nil
}
but also same type could be used for other tracing at the nats level with implementing the nats.Option:
func WithClientTrace(ct *ClientTrace) Option {
return func(o *Options) error {
// Trace funcs but at the NATS level
o.ClientTrace = ct
return nil
}
}
Then could use either later on:
// Define at the NATS level to trace protocols or non JS traffic as well:
nc, err := Connect(s.ClientURL(), WithClientTrace(&ClientTrace{}))
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
defer nc.Close()
// Trace funcs scoped at the JS level. Implements the interface for
// JS option so can use the same type.
nc, _ = Connect(s.ClientURL())
js, err := nc.JetStream(&ClientTrace{
RequestSent: func(subj string, payload []byte, hdr Header) {
fmt.Println(">>> SENT : ", subj, payload)
},
ResponseReceived: func(subj string, payload []byte, hdr Header) {
fmt.Println("<<< RECVD: ", subj, payload)
},
})
(Put an example of how this would look here: wallyqs@2a8553d#diff-d3e5f2fc32ab57ad01ff7eff1dc643653af5636e517a4b0677ddcefb94f87f7bR909)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have a baked example feel free to put up a PR instead of this one, I dont mind who puts it in :) just need to be able to get tracing on things as debugging stuff atm is really tough :)
I wont have time to work on this past whats here for like week and a half
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, ok maybe let's include as is for now to iterate on the idea already in main branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: R.I.Pienaar rip@devco.net