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

Adding "hooks" for logging/tracing/... #3

Open
olivierlemasle opened this issue Jul 27, 2021 · 1 comment
Open

Adding "hooks" for logging/tracing/... #3

olivierlemasle opened this issue Jul 27, 2021 · 1 comment

Comments

@olivierlemasle
Copy link
Contributor

This issue is a follow-up of xanzy/go-cloudstack#120.

That issue was opened by @synergiator with the title "How to change the log level for go-cloudstack module?" and asked for a way to have more detailed logging.

I proposed a broader solution:

I also think that adding logging would be useful, but as there's never consensus on what to log or which logging library to use (log, zap, logrus, etc.), what would you think of adding some "hooks", optional functions that would be called before and after the actual http request? The user of CloudStack client could then provide its own logging or tracing logic.

IMHO, the best would be to also add an optional context.Context to all API functions, in order to make it possible to do contextual tracing for example.

A possible signature for these hooks could be:

// PreRequestHook would be called in newRequest, just before the HTTP request call.
type PreRequestHook func(ctx context.Context, api string, params url.Values)

// PostRequestHook would be called in each generated client function,
// just after the Unmarshal step.
type PostRequestHook func(ctx context.Context, rawResp json.RawMessage, err error, resp interface{})

I can contribute and submit a PR if you are ok with that.

Any thoughts?

@rohityadavcloud
Copy link
Member

I've not idea as I'm not a Go expert, I can ask @svanharmelen @davidjumani @Pearl1594 to chime in, or ask you to start a [DISCUSS] thread if it's a large issue you want to discuss on the dev@ mailing list.

vishesh92 pushed a commit that referenced this issue Mar 13, 2024
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

No branches or pull requests

2 participants