apache / apache/cloudstack-go

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

未关闭
#3 1 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Go
星标
39
派生
47
PR 合并指标
30 天内没有已合并 PR

描述

This issue is a follow-up of https://github.com/xanzy/go-cloudstack/issues/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:
>
> ```go
> // 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?

贡献指南

这个仓库没有索引到贡献指南

调研方向

阅读关于日志记录以及所提议的 PreRequestHook 和 PostRequestHook 签名的关联 issue。检查 newRequest 和生成的客户端函数,以了解 hooks 和可选 context 将在哪里应用。只有当项目对 request hooks 和 context 传播形成一致的设计,而不仅仅是一个总体提案时,才算完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
go
领域
api
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
20/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。