Skip to content
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

Add ClientTrace struct for JS tracing #911

Merged
merged 1 commit into from
Mar 29, 2022
Merged

Add ClientTrace struct for JS tracing #911

merged 1 commit into from
Mar 29, 2022

Conversation

wallyqs
Copy link
Member

@wallyqs wallyqs commented Feb 16, 2022

This is an alternative implementation to enable tracing of requests in the JetStream context #849, using the same idiom of a struct with callbacks as the httptrace package (https://golang.google.cn/pkg/net/http/httptrace/#ClientTrace).

	js, err := nc.JetStream(&ClientTrace{
		RequestSent: func(subj string, payload []byte) {
			log.Printf(">>> %s: %s", subj, string(payload))
		},
		ResponseReceived: func(subj string, payload []byte, hdr Header) {
			log.Printf("<<< %s: %s", subj, string(payload))
		},
	})

Signed-off-by: Waldemar Quevedo wally@synadia.com

@wallyqs wallyqs requested review from kozlovic and ripienaar and removed request for kozlovic February 16, 2022 20:25
@wallyqs
Copy link
Member Author

wallyqs commented Feb 16, 2022

If this is ok then will make the change for the natscli, it is a small change: https://github.com/nats-io/natscli/blob/6accd61459f59cbb26e6e14cc24b3606ffc7b426/cli/util.go#L448-L454

@coveralls
Copy link

coveralls commented Feb 16, 2022

Coverage Status

Coverage decreased (-0.04%) to 85.104% when pulling f658a93 on with-client-trace into 5753a5f on main.

// ClientTrace can be used to trace API interactions for the JetStream Context.
type ClientTrace struct {
RequestSent func(subj string, payload []byte, hdr Header)
ResponseReceived func(subj string, payload []byte, hdr Header)
Copy link
Member Author

Choose a reason for hiding this comment

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

We could expand this to make them more granular for example, to only trace consumer lookups or for when adding retries make it possible to log an event for when there is a backoff, etc...

Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

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

I like the approach, but of course this is again breaking changes (we had just one in previous PR for the KV purge options). I guess we mentioned that the JS/KV API may change, but hopefully we start to be more stable soon.

js.go Outdated Show resolved Hide resolved
js.go Outdated Show resolved Hide resolved
js.go Show resolved Hide resolved
Copy link
Member

@kozlovic kozlovic left a 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: Waldemar Quevedo <wally@synadia.com>
@wallyqs
Copy link
Member Author

wallyqs commented Mar 29, 2022

This one is ready to merge, follow up PR with the natscli changes here: https://github.com/nats-io/natscli/tree/with-client-trace

@wallyqs wallyqs merged commit ce33b19 into main Mar 29, 2022
@wallyqs wallyqs deleted the with-client-trace branch March 29, 2022 17:00
wallyqs added a commit that referenced this pull request Mar 29, 2022
Add ClientTrace struct for JS tracing

Signed-off-by: Waldemar Quevedo <wally@nats.io>
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.

3 participants