-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Optimizing hertz observability (#845)
Signed-off-by: rogerogers <[email protected]>
- Loading branch information
1 parent
27cbcf7
commit 804f238
Showing
9 changed files
with
134 additions
and
44 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
content/en/docs/hertz/tutorials/observability/instrumentation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
title: "Instrumentation" | ||
date: 2023-10-28 | ||
weight: 3 | ||
keywords: ["Hertz", "Stats", "Instrumentation"] | ||
description: Hertz supports flexible enabling of basic and fine-grained Instrumentation | ||
--- | ||
|
||
## Stats Level | ||
|
||
| Option | Description | Enable Strategy | | ||
| ------------- | --------------------------------------- | ------------------------------------------------ | | ||
| LevelDisabled | disable all events | When tracer is not available, enable by default. | | ||
| LevelBase | enable basic events | | | ||
| LevelDetailed | enable basic events and detailed events | When tracer is available, enable by default. | | ||
|
||
## Stats Level Control | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/cloudwego/hertz/pkg/app/server" | ||
"github.com/cloudwego/hertz/pkg/common/tracer/stats" | ||
) | ||
|
||
func main() { | ||
h := server.Default(server.WithTraceLevel(stats.LevelBase)) | ||
h.Spin() | ||
} | ||
``` | ||
|
||
## Stats introduction | ||
|
||
### Basic Stats Event | ||
|
||
1. `HTTPStart` : Http start | ||
2. `HTTPFinish` : Http finish | ||
|
||
### Detailed Stats Event | ||
|
||
1. `ReadHeaderStart`:read header start | ||
2. `ReadHeaderFinish`:read header finish | ||
3. `ReadBodyStart`:read body start | ||
4. `ReadBodyFinish`:read body finish | ||
5. `ServerHandleStart`:server handler start | ||
6. `ServerHandleFinish`:server handler finish | ||
7. `WriteStart`:write response start | ||
8. `WriteFinish`:write response finish | ||
|
||
> If you do not want to record this information, you can either not register any tracer or set the tracking strategy to LevelDisabled, and the framework will not record this information. | ||
> | ||
> - **Setting the stats level of a certain node in the tracing to `LevelDisabled` will result in the loss of spans/metrics for that node, but it will not cause the tracing to be interrupted.** | ||
> - **Not registering any tracer will also result in the loss of spans/metrics for that node, and it will also cause the tracing to be interrupted.** | ||
### Timeline | ||
|
||
![timeline](/img/docs/hertz_tracing_timeline.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
content/en/docs/hertz/tutorials/observability/open-telemetry.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
content/zh/docs/hertz/tutorials/observability/instrumentation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
title: "埋点" | ||
date: 2023-10-28 | ||
weight: 3 | ||
keywords: ["Hertz", "Stats", "Instrumentation"] | ||
description: Hertz 支持灵活启用基本埋点和细粒度埋点 | ||
--- | ||
|
||
## 埋点粒度 | ||
|
||
| 参数 | 介绍 | 启用策略 | | ||
| ------------- | ------------------------ | ---------------------- | | ||
| LevelDisabled | 禁用埋点 | 无 tracer 时,默认启用 | | ||
| LevelBase | 仅启用基本埋点 | | | ||
| LevelDetailed | 启用基本埋点和细粒度埋点 | 有 tracer 时,默认启用 | | ||
|
||
## 埋点粒度控制 | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/cloudwego/hertz/pkg/app/server" | ||
"github.com/cloudwego/hertz/pkg/common/tracer/stats" | ||
) | ||
|
||
func main() { | ||
h := server.Default(server.WithTraceLevel(stats.LevelBase)) | ||
h.Spin() | ||
} | ||
``` | ||
|
||
## 埋点说明 | ||
|
||
### 基本埋点 | ||
|
||
1. `HTTPStart` : 请求开始 | ||
2. `HTTPFinish` : 请求结束 | ||
|
||
### 细粒度埋点 | ||
|
||
1. `ReadHeaderStart`:读取 header 开始 | ||
2. `ReadHeaderFinish`:读取 header 结束 | ||
3. `ReadBodyStart`:读取 body 开始 | ||
4. `ReadBodyFinish`:读取 body 结束 | ||
5. `ServerHandleStart`:业务 handler 开始 | ||
6. `ServerHandleFinish`:业务 handler 结束 | ||
7. `WriteStart`:写 response 开始 | ||
8. `WriteFinish`:写 response 结束 | ||
|
||
> 如果不希望记录这些信息,可以不注册任何 tracer 或者将埋点策略设置为 `LevelDisabled`,则框架不会记录这些信息。 | ||
> | ||
> - **将链路中某节点埋点策略设置为 `LevelDisabled`,会导致本节点 span/matrics 丢失,不会导致链路中断** | ||
> - **不注册任何 tracer,也会导致本节点 span/metrics 丢失,同时也会导致链路中断** | ||
### 时序图 | ||
|
||
![timeline](/img/docs/hertz_tracing_timeline.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
--- | ||
title: "监控" | ||
linkTitle: "监控" | ||
weight: 3 | ||
weight: 4 | ||
keywords: ["监控"] | ||
description: "Hertz 提供的监控能力。" | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
content/zh/docs/hertz/tutorials/observability/open-telemetry.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
804f238
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
cloudwego – ./
cloudwego-cloudwego.vercel.app
cloudwego-git-main-cloudwego.vercel.app
www.cloudwego.io
cloudwego.vercel.app
vercel.cloudwego.io
cloudwego.io