gotosocial/docs/locales/zh/advanced/tracing.md
tobi 82216281ce [chore/docs] Fix Prometheus metric names for Gin, include example Grafana dash, update docs (#4443)
# Description

> If this is a code change, please include a summary of what you've coded, and link to the issue(s) it closes/implements.
>
> If this is a documentation change, please briefly describe what you've changed and why.

This pull request updates some of our inconsistent metric naming, and adds an example Grafana dashboard using all the most up-to-date metrics names, and updates our docs to describe the latest way of setting up metrics.

Closes https://codeberg.org/superseriousbusiness/gotosocial/issues/4362
Closes https://codeberg.org/superseriousbusiness/gotosocial/issues/4055

## Checklist

Please put an x inside each checkbox to indicate that you've read and followed it: `[ ]` -> `[x]`

If this is a documentation change, only the first checkbox must be filled (you can delete the others if you want).

- [x] I/we have read the [GoToSocial contribution guidelines](https://codeberg.org/superseriousbusiness/gotosocial/src/branch/main/CONTRIBUTING.md).
- [x] I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat.
- [x] I/we have not leveraged AI to create the proposed changes.
- [x] I/we have performed a self-review of added code.
- [x] I/we have written code that is legible and maintainable by others.
- [x] I/we have commented the added code, particularly in hard-to-understand areas.
- [x] I/we have made any necessary changes to documentation.
- [ ] I/we have added tests that cover new code.
- [x] I/we have run tests and they pass locally with the changes.
- [x] I/we have run `go fmt ./...` and `golangci-lint run`.

Co-authored-by: kim <grufwub@gmail.com>
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4443
Reviewed-by: kim <gruf@noreply.codeberg.org>
Co-authored-by: tobi <tobi.smethurst@protonmail.com>
Co-committed-by: tobi <tobi.smethurst@protonmail.com>
2025-09-18 16:48:45 +02:00

2.3 KiB
Raw Blame History

追踪

GoToSocial 内置了基于 OpenTelemetry 的追踪功能。虽然并没有贯穿每个函数,但我们的 HTTP 处理程序和数据库库会创建跨度。在 可观测性配置参考 中解释了如何配置追踪。

为了接收这些追踪,你需要一些工具来摄取并可视化它们。有很多选项,包括自托管和商业选项。

我们提供了一个示例,说明如何使用 Grafana Tempo 来抓取数据跨度,并使用 Grafana 来检索它们。请注意,我们提供的配置不适合生产环境。可以安全地用于本地开发,并可为设置你自己的追踪基础设施提供一个良好的起点。

你需要获取 example/tracing 中的文件。获取这些文件后,你可以运行 docker-compose up -d 来启动 Tempo 和 Grafana。在两个服务运行后可以将以下内容添加到 GoToSocial 配置中,并重新启动你的实例:

tracing-enabled: true
tracing-transport: "grpc"
tracing-endpoint: "localhost:4317"
tracing-insecure-transport: true

查询和可视化追踪

在对你的实例执行几个查询后,你可以在 Grafana 中找到它们。你可以使用 Explore 选项卡并选择 Tempo 作为数据源。由于我们的 Grafana 示例配置启用了 TraceQLExplore 选项卡将默认选择 TraceQL 查询类型。你可以改为选择“搜索”并在“GoToSocial”服务名称下找到所有 GoToSocial 发出的追踪。

使用 TraceQL 时,一个简单的查询来查找与 /api/v1/instance 请求相关的所有追踪可以这样写:

{.http.route = "/api/v1/instance"}

如果你想查看所有 GoToSocial 追踪,可以运行:

{.service.name = "GoToSocial"}

选择一个追踪后,将打开第二个面板,显示对应数据跨度的可视化视图。你可以从那里深入浏览,通过点击每个子跨度查看其执行的操作。

Grafana 显示 /api/v1/instance 端点的追踪