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

链路追踪 #9

Open
lc-1010 opened this issue Jun 21, 2023 · 1 comment
Open

链路追踪 #9

lc-1010 opened this issue Jun 21, 2023 · 1 comment

Comments

@lc-1010
Copy link
Owner

lc-1010 commented Jun 21, 2023

  • openTracing
  • jaeger
  • 日志追踪
  • SQL 追踪
lc-1010 added a commit that referenced this issue Jul 1, 2023
This commit adds a function comment for the Tracing middleware handler in the Go file  internal/middleware/tracer.go.

#9
lc-1010 added a commit that referenced this issue Jul 2, 2023
…try'

The 'opentracing-go' package has been deprecated, so this commit replaces the import paths from 'github.com/opentracing/opentracing-go' to 'go.opentelemetry.io/otel'. This ensures compatibility with the latest tracing libraries and best practices.
and opentracing-go repository has been archived by the owner on May 24, 2023. It is now read-only.
opentracing/specification#163

ref #9
@lc-1010
Copy link
Owner Author

lc-1010 commented Jul 3, 2023

TraceId 和SpanId 设计的参考

TraceId 来将一个请求在各个服务器上的调用日志串联起来,TraceId 一般由接收请求经过的第一个服务器产生。

  • TraceId 生成规则
    • TraceId 来将一个请求在各个服务器上的调用日志串联起来,TraceId 一般由接收请求经过的第一个服务器产生。
      产生规则是: 服务器 IP + ID 产生的时间 + 自增序列 + 当前进程号0ad1348f1403169275002100356696
      前 8 位 0ad1348f 即产生 TraceId 的机器的 IP,这是一个十六进制的数字,每两位代表 IP 中的一段,我们把这个数字,按每两位转成 10 进制即可得到常见的 IP 地址表示方式 10.209.52.143,您也可以根据这个规律来查找到请求经过的第一个服务器。
      后面的 13 位 1403169275002 是产生 TraceId 的时间。之后的 4 位 1003 是一个自增的序列,从 1000 涨到 9000,到达 9000 后回到 1000 再开始往上涨。最后的 5 位 56696 是当前的进程 ID,为了防止单机多进程出现 TraceId 冲突的情况,所以在 TraceId 末尾添加了当前的进程 ID。

SpanId 代表本次调用在整个调用链路树中的位置。

假设一个 Web 系统 A 接收了一次用户请求,那么在这个系统的 MVC 日志中,记录下的 SpanId 是 0,代表是整个调用的根节点,如果 A 系统处理这次请求,需要通过 RPC 依次调用 B、C、D 三个系统,那么在 A 系统的 RPC 客户端日志中,SpanId 分别是 0.1,0.2 和 0.3,在 B、C、D 三个系统的 RPC 服务端日志中,SpanId 也分别是 0.1,0.2 和 0.3;如果 C 系统在处理请求的时候又调用了 E,F 两个系统,那么 C 系统中对应的 SOFATracer RPC 客户端日志是 0.2.1 和 0.2.2,E、F 两个系统对应的 SOFATracer RPC 服务端日志也是 0.2.1 和 0.2.2

lc-1010 added a commit that referenced this issue Jul 3, 2023
- Add tracing to API requests using a trace plugin
- Configure GORM to trace SQL queries
- Optimize and improve the code

#9
lc-1010 added a commit that referenced this issue Jul 6, 2023
- Update tracing to log request and SQL in the same log

This commit adds the 'gorm.io/plugin/opentelemetry/tracing' package to enable context tracing with 'opentelemetry' for SQL queries. It also modifies the tracing implementation to include both the request and SQL in the log. The request information is now included as an attribute in the span, and the query callback function is updated to log the request, SQL, and table information.

These changes improve the visibility and traceability of requests and SQL queries, providing a consolidated log for easier debugging and monitoring.
#9
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

1 participant