Skip to content

Commit cdb6740

Browse files
minimAluminiumalismwilsonxscai
authored and
wilsonxscai
committed
update span name based on latest semconv
2 parents 01df671 + 69542aa commit cdb6740

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+803
-246
lines changed

Diff for: .gitignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,4 @@ test/golog/test_glog
3434
test/grpc/v1.44.0/test_grpc_basic
3535
test/fasthttp/v1.45.0/test_basic_http
3636
test/hertz/v0.9.0/test_hertz_basic
37-
test/world/world
38-
39-
coverage.txt
37+
test/world/world

Diff for: README.md

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
![](docs/anim-logo.svg)
22

3-
[![](https://shields.io/badge/Docs-English-blue?logo=Read%20The%20Docs)](./docs/README.md)
3+
[![](https://shields.io/badge/Docs-English-blue?logo=Read%20The%20Docs)](./README.md)
44
[![](https://shields.io/badge/Readme-中文-blue?logo=Read%20The%20Docs)](./docs/README_CN.md)
55
[![codecov](https://codecov.io/gh/alibaba/opentelemetry-go-auto-instrumentation/branch/main/graph/badge.svg)](https://codecov.io/gh/alibaba/opentelemetry-go-auto-instrumentation)
6+
[![](https://shields.io/badge/Commercial-Aliyun-orange?logo=alibabacloud)](https://help.aliyun.com/zh/arms/application-monitoring/getting-started/monitoring-the-golang-applications)
67

78
This project provides an automatic solution for Golang applications that want to
89
leverage OpenTelemetry to enable effective observability. No code changes are
@@ -44,23 +45,22 @@ The configuration for the tool can be set by the following command:
4445

4546
```bash
4647
$ otel set -verbose # print verbose logs
47-
$ otel set -log=/path/to/file.log # set log file
4848
$ otel set -debug # enable debug mode
49-
$ otel set -debug -verbose -rule=custom.json # set multiple configs
50-
$ otel set -disabledefault -rule=custom.json # disable default rules, use custom rules only
5149
$ otel set -rule=custom.json # use default and custom rules
52-
$ otel set -rule=a.json,b.json # use default, a and b rules
50+
$ otel set -debug -verbose -rule=custom.json # set multiple configs
5351
```
5452

55-
Once all set up, add `otel` prefix to `go build` to build your project:
53+
Normally, you don't need to set any configurations. Just adding `otel` prefix to `go build` to build your project:
5654

5755
```bash
5856
$ otel go build
5957
$ otel go build -o app cmd/app
6058
$ otel go build -gcflags="-m" cmd/app
6159
```
6260

63-
The detailed usage of otel tool can be found in [**Usage**](./docs/usage.md).
61+
That's the whole process! The tool will automatically instrument your code with OpenTelemetry, and you can start to observe your application. :telescope:
62+
63+
The detailed usage of `otel` tool can be found in [**Usage**](./docs/usage.md).
6464

6565
> [!NOTE]
6666
> If you find any compilation failures while `go build` works, it's likely a bug.
@@ -114,6 +114,19 @@ We are progressively open-sourcing the libraries we have supported, and your con
114114
>
115115
> Please refer to [this document](./docs/how-to-add-a-new-rule.md) to get started.
116116
117+
# Documentation
118+
119+
- [How to add a new rule](./docs/how-to-add-a-new-rule.md)
120+
- [How to write tests for plugins](./docs/how-to-write-tests-for-plugins.md)
121+
- [Compatibility](./docs/compatibility.md)
122+
- [How it works](./docs/how-it-works.md)
123+
- [How to debug](./docs/how-to-debug.md)
124+
- [Context Propagation](./docs/context-propagation.md)
125+
- [Supported Libraries](./docs/supported-libraries.md)
126+
- [Benchmark](./example/benchmark/benchmark.md)
127+
- [Discussion on this topic at OpenTelemetry community](https://github.com/open-telemetry/community/issues/1961)
128+
- [面向OpenTelemetry的Golang应用无侵入插桩技术](https://mp.weixin.qq.com/s/FKCwzRB5Ujhe1stOH2ibXg)
129+
117130
# Community
118131

119132
We are looking forward to your feedback and suggestions. You can join
@@ -140,7 +153,7 @@ These are only part of the companies using this project, for reference only. If
140153
[![Star History](https://api.star-history.com/svg?repos=alibaba/opentelemetry-go-auto-instrumentation&type=Date)](https://star-history.com/#alibaba/opentelemetry-go-auto-instrumentation&Date)
141154

142155
<p align="right" style="font-size: 14px; color: #555; margin-top: 20px;">
143-
<a href="#readme-top" style="text-decoration: none; color: #007bff; font-weight: bold;">
144-
返回顶部
156+
<a href="#Installation" style="text-decoration: none; color: #007bff; font-weight: bold;">
157+
TOP
145158
</a>
146159
</p>

Diff for: docs/README.md

-13
This file was deleted.

Diff for: docs/README_CN.md

+71-14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
![](anim-logo.svg)
22

3-
[![](https://shields.io/badge/Docs-English-blue?logo=Read%20The%20Docs)](./README.md)
3+
[![](https://shields.io/badge/Docs-English-blue?logo=Read%20The%20Docs)](../README.md)
44
[![](https://shields.io/badge/Readme-中文-blue?logo=Read%20The%20Docs)](./README_CN.md)
55
[![codecov](https://codecov.io/gh/alibaba/opentelemetry-go-auto-instrumentation/branch/main/graph/badge.svg)](https://codecov.io/gh/alibaba/opentelemetry-go-auto-instrumentation)
66

77
该项目为希望利用 OpenTelemetry 的 Golang 应用程序提供了一个自动解决方案。
88
利用 OpenTelemetry 实现有效可观察性的 Golang 应用程序提供自动解决方案。目标应用程序无需更改代码
9-
在编译时完成。只需在 `go build` 中添加 `otel` 前缀即可开始 :rocket
9+
在编译时完成。只需在 `go build` 中添加 `otel` 前缀即可开始 :rocket:
1010

1111
# 安装
1212

@@ -20,18 +20,35 @@ $ sudo curl -fsSL https://cdn.jsdelivr.net/gh/alibaba/opentelemetry-go-auto-inst
2020
### 预编译二进制文件
2121

2222
请从
23-
Release](https://github.com/alibaba/opentelemetry-go-auto-instrumentation/releases)
23+
[Release](https://github.com/alibaba/opentelemetry-go-auto-instrumentation/releases)
2424
页面下载最新的预编译版本。
2525

2626
### 从源代码编译
2727

2828
通过运行以下命令查看源代码并构建工具:
2929

3030
```bash
31-
$ make build
31+
$ make # 只构建
32+
$ make install # 构建并安装
3233
```
3334

34-
### 开始
35+
# 开始
36+
37+
通过运行以下命令检查版本:
38+
```bash
39+
$ otel version
40+
```
41+
42+
通过以下命令配置工具参数:
43+
```bash
44+
$ otel set -verbose # 打印详细日志
45+
$ otel set -log=/path/to/file.log # 设置日志文件路径
46+
$ otel set -debug # 启用调试模式
47+
$ otel set -debug -verbose -rule=custom.json # 组合配置参数
48+
$ otel set -disabledefault -rule=custom.json # 禁用默认规则,仅使用自定义规则
49+
$ otel set -rule=custom.json # 同时使用默认和自定义规则
50+
$ otel set -rule=a.json,b.json # 使用默认规则及 a 和 b 自定义规则
51+
```
3552

3653
`go build` 中添加 `otel` 前缀,以构建项目:
3754

@@ -49,16 +66,20 @@ $ otel -verbose go build # 打印详细日志
4966
$ otel -rule=custom.json go build # 使用自定义规则
5067
```
5168

69+
您可以在 [**使用指南**](./usage.md)中找到 `otel` 工具的详细用法。
70+
71+
> [!NOTE]
72+
> 如果您发现任何编译失败,而 `go build` 却能正常工作,这很可能是一个 bug。
73+
> 请随时在
74+
> [GitHub Issues](https://github.com/alibaba/opentelemetry-go-auto-instrumentation/issues)
75+
> 提交问题报告以帮助我们改进本项目。
76+
77+
# 示例
78+
5279
您还可以探索 [**这些示例**](../example/) 以获得实践经验。
5380

5481
此外,还有一些 [**文档**](../docs),您可能会发现它们对了解项目或为项目做出贡献非常有用。
5582

56-
> 注意
57-
> 如果你发现任何编译失败,而 `go build` 却能正常工作,这很可能是一个 bug。
58-
> 请随时在
59-
> 请随时在 [GitHub Issues](https://github.com/alibaba/opentelemetry-go-auto-instrumentation/issues)
60-
> 以帮助我们改进本项目。
61-
6283
# 支持的库
6384

6485
| 插件名称 | 存储库网址 | 最低支持版本 | 最高支持版本 |
@@ -94,14 +115,50 @@ $ otel -rule=custom.json go build # 使用自定义规则
94115

95116
我们正在逐步开源我们支持的库,非常欢迎您的贡献💖!
96117

97-
> 重要事项
98-
> 您期望的框架不在列表中?别担心,你可以轻松地将代码注入到任何官方不支持的框架/库中。
118+
> [!IMPORTANT]
119+
> 您期望的框架不在列表中?别担心,您可以轻松地将代码注入到任何官方不支持的框架/库中。
99120
>
100-
> 请参考 [this document](./how-to-add-a-new-rule.md) 开始使用。
121+
> 请参考 [这个文档](./how-to-add-a-new-rule.md) 开始使用。
122+
123+
# 文档
124+
125+
- [如何添加新规则](./how-to-add-a-new-rule.md)
126+
- [如何编写插件测试](./how-to-write-tests-for-plugins.md)
127+
- [兼容性说明](./compatibility.md)
128+
- [实现原理](./how-it-works.md)
129+
- [如何调试](./how-to-debug.md)
130+
- [上下文传播机制](./context-propagation.md)
131+
- [支持的库](./supported-libraries.md)
132+
- [基准测试](../example/benchmark/benchmark.md)
133+
- [OpenTelemetry社区讨论主题](https://github.com/open-telemetry/community/issues/1961)
134+
- [面向OpenTelemetry的Golang应用无侵入插桩技术](https://mp.weixin.qq.com/s/FKCwzRB5Ujhe1stOH2ibXg)
101135

102136
# 社区
103137

104138
我们期待您的反馈和建议。您可以加入我们的 [DingTalk 群组](https://qr.dingtalk.com/action/joingroup?code=v1,k1,GyDX5fUTYnJ0En8MrVbHBYTGUcPXJ/NdsmLODGibd0w=&_dt_no_comment=1&origin=11? )
105139
与我们交流。
106140

107141
<img src="dingtalk.png" height="200">
142+
143+
# 应用案例
144+
145+
以下为部分采用本项目的企业列表,仅供参考。如果您正在使用此项目,请[在此处添加您的公司](https://github.com/alibaba/opentelemetry-go-auto-instrumentation/issues/225)告诉我们您的使用场景,让这个项目变得更好。
146+
147+
- <img src="./alibaba.png" width="80">
148+
- <img src="./aliyun.png" width="100">
149+
150+
# Contributors
151+
152+
<a href="https://github.com/alibaba/opentelemetry-go-auto-instrumentation/graphs/contributors">
153+
<img alt="contributors" src="https://contrib.rocks/image?repo=alibaba/opentelemetry-go-auto-instrumentation"/>
154+
</a>
155+
156+
# Star History
157+
158+
[![Star History](https://api.star-history.com/svg?repos=alibaba/opentelemetry-go-auto-instrumentation&type=Date)](https://star-history.com/#alibaba/opentelemetry-go-auto-instrumentation&Date)
159+
160+
<p align="right" style="font-size: 14px; color: #555; margin-top: 20px;">
161+
<a href="#安装" style="text-decoration: none; color: #007bff; font-weight: bold;">
162+
↑ 返回顶部 ↑
163+
</a>
164+
</p>

Diff for: docs/rule_def.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Instument a function
44
- `ImportPath`: The import path of the package that contains the function to be instrumented. e.g. `net/http`.
5-
- `Function`: The name of the function to be instrumented.
5+
- `Function`: The name of the function to be instrumented, it could be a regular expression to match multiple functions. e.g. `.*` matches all functions in the package, `.*ServeHTTP` matches all functions whose name ends with `ServeHTTP`, and so on.
66
- `ReceiverType`: The type of the receiver of the function to be instrumented. e.g. `*http.Server`, `http.Server`.
77
- `OnEnter`: The name of the function to be called when the instrumented function is called. e.g. `clientOnEnter`.
88
- `OnExit`: The name of the function to be called when the instrumented function returns. e.g. `clientOnExit`.

Diff for: example/extension/nethttp/rules/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module netHttp
22

3-
go 1.22.7
3+
go 1.23
44

55
toolchain go1.23.3
66

Diff for: example/extension/sqlinject/rules/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module sqlinject
22

3-
go 1.22.7
3+
go 1.23
44

55
toolchain go1.23.3
66

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/alibaba/opentelemetry-go-auto-instrumentation
22

3-
go 1.23
3+
go 1.23.0
44

55
replace github.com/alibaba/opentelemetry-go-auto-instrumentation/test/verifier => ./test/verifier
66

Diff for: pkg/data/test_error.json

+12
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,17 @@
112112
"Function": "TargetWithFuncType",
113113
"OnEnter": "onEnterTargetWithFuncType",
114114
"Path": "github.com/alibaba/opentelemetry-go-auto-instrumentation/pkg/rules/test/error18"
115+
},
116+
{
117+
"ImportPath": "errorstest/all",
118+
"Function": ".*",
119+
"OnEnter": "onEnterGeneric",
120+
"Path": "github.com/alibaba/opentelemetry-go-auto-instrumentation/pkg/rules/test/error19"
121+
},
122+
{
123+
"ImportPath": "errorstest/all",
124+
"Function": "f[12]",
125+
"OnEnter": "onEnterGeneric2",
126+
"Path": "github.com/alibaba/opentelemetry-go-auto-instrumentation/pkg/rules/test/error19"
115127
}
116128
]

Diff for: pkg/inst-api-semconv/instrumenter/ai/ai_attrs_extractor.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ package ai
1717
import (
1818
"context"
1919
"go.opentelemetry.io/otel/attribute"
20-
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
20+
semconv "go.opentelemetry.io/otel/semconv/v1.30.0"
2121
)
2222

23-
//待semconv统一更新到v1.30.0后更新OnStart中键值使用方式
23+
// TODO: remove server.address and put it into NetworkAttributesExtractor
2424

2525
type AICommonAttrsExtractor[REQUEST any, RESPONSE any, GETTER1 CommonAttrsGetter[REQUEST, RESPONSE]] struct {
2626
CommonGetter GETTER1
@@ -29,10 +29,10 @@ type AICommonAttrsExtractor[REQUEST any, RESPONSE any, GETTER1 CommonAttrsGetter
2929

3030
func (h *AICommonAttrsExtractor[REQUEST, RESPONSE, GETTER1]) OnStart(attributes []attribute.KeyValue, parentContext context.Context, request REQUEST) ([]attribute.KeyValue, context.Context) {
3131
attributes = append(attributes, attribute.KeyValue{
32-
Key: "gen_ai.operation.name", //semconv.GenAIOperationNameKey
32+
Key: semconv.GenAIOperationNameKey,
3333
Value: attribute.StringValue(h.CommonGetter.GetAIOperationName(request)),
3434
}, attribute.KeyValue{
35-
Key: "gen_ai.system", //semconv.GenAISystemKey
35+
Key: semconv.GenAISystemKey,
3636
Value: attribute.StringValue(h.CommonGetter.GetAISystem(request)),
3737
})
3838
return attributes, parentContext
@@ -56,40 +56,40 @@ type AILLMAttrsExtractor[REQUEST any, RESPONSE any, GETTER1 CommonAttrsGetter[RE
5656
func (h *AILLMAttrsExtractor[REQUEST, RESPONSE, GETTER1, GETTER2]) OnStart(attributes []attribute.KeyValue, parentContext context.Context, request REQUEST) ([]attribute.KeyValue, context.Context) {
5757
attributes, parentContext = h.Base.OnStart(attributes, parentContext, request)
5858
attributes = append(attributes, attribute.KeyValue{
59-
Key: "gen_ai.request.model", //semconv.GenAIRequestModelKey
59+
Key: semconv.GenAIRequestModelKey,
6060
Value: attribute.StringValue(h.LLMGetter.GetAIRequestModel(request)),
6161
}, attribute.KeyValue{
62-
Key: "gen_ai.request.encoding_formats", //semconv.GenAIRequestEncodingFormatsKey
62+
Key: semconv.GenAIRequestEncodingFormatsKey,
6363
Value: attribute.StringSliceValue(h.LLMGetter.GetAIRequestEncodingFormats(request)),
6464
}, attribute.KeyValue{
65-
Key: "gen_ai.request.max_tokens", //semconv.GenAIRequestMaxTokensKey
65+
Key: semconv.GenAIRequestMaxTokensKey,
6666
Value: attribute.Int64Value(h.LLMGetter.GetAIRequestMaxTokens(request)),
6767
}, attribute.KeyValue{
68-
Key: "gen_ai.request.frequency_penalty", //semconv.GenAIRequestFrequencyPenaltyKey,
68+
Key: semconv.GenAIRequestFrequencyPenaltyKey,
6969
Value: attribute.Float64Value(h.LLMGetter.GetAIRequestFrequencyPenalty(request)),
7070
}, attribute.KeyValue{
71-
Key: "gen_ai.request.presence_penalty", //semconv.GenAIRequestPresencePenaltyKey,
71+
Key: semconv.GenAIRequestPresencePenaltyKey,
7272
Value: attribute.Float64Value(h.LLMGetter.GetAIRequestPresencePenalty(request)),
7373
}, attribute.KeyValue{
74-
Key: "gen_ai.request.stop_sequences", //semconv.GenAIRequestStopSequencesKey,
74+
Key: semconv.GenAIRequestStopSequencesKey,
7575
Value: attribute.StringSliceValue(h.LLMGetter.GetAIRequestStopSequences(request)),
7676
}, attribute.KeyValue{
77-
Key: "gen_ai.request.temperature", //semconv.GenAIRequestTemperatureKey,
77+
Key: semconv.GenAIRequestTemperatureKey,
7878
Value: attribute.Float64Value(h.LLMGetter.GetAIRequestTemperature(request)),
7979
}, attribute.KeyValue{
80-
Key: "gen_ai.request.top_k", //semconv.GenAIRequestTopKKey,
80+
Key: semconv.GenAIRequestTopKKey,
8181
Value: attribute.Float64Value(h.LLMGetter.GetAIRequestTopK(request)),
8282
}, attribute.KeyValue{
83-
Key: "gen_ai.request.top_p", //semconv.GenAIRequestTopPKey,
83+
Key: semconv.GenAIRequestTopPKey,
8484
Value: attribute.Float64Value(h.LLMGetter.GetAIRequestTopP(request)),
8585
}, attribute.KeyValue{
86-
Key: "gen_ai.usage.input_tokens", //semconv.GenAIUsageInputTokensKey,
86+
Key: semconv.GenAIUsageInputTokensKey,
8787
Value: attribute.Int64Value(h.LLMGetter.GetAIUsageInputTokens(request)),
8888
}, attribute.KeyValue{
8989
Key: semconv.ServerAddressKey,
9090
Value: attribute.StringValue(h.LLMGetter.GetAIServerAddress(request)),
9191
}, attribute.KeyValue{
92-
Key: "gen_ai.request.seed", //semconv.GenAIRequestSeedKey,
92+
Key: semconv.GenAIRequestSeedKey,
9393
Value: attribute.Int64Value(h.LLMGetter.GetAIRequestSeed(request)),
9494
})
9595
if h.Base.AttributesFilter != nil {
@@ -101,19 +101,19 @@ func (h *AILLMAttrsExtractor[REQUEST, RESPONSE, GETTER1, GETTER2]) OnEnd(attribu
101101
attributes, context = h.Base.OnEnd(attributes, context, request, response, err)
102102

103103
attributes = append(attributes, attribute.KeyValue{
104-
Key: "gen_ai.response.finish_reasons", //semconv.GenAIResponseFinishReasonsKey,
104+
Key: semconv.GenAIResponseFinishReasonsKey,
105105
Value: attribute.StringSliceValue(h.LLMGetter.GetAIResponseFinishReasons(request, response)),
106106
}, attribute.KeyValue{
107-
Key: "gen_ai.response.id", //semconv.GenAIResponseIDKey,
107+
Key: semconv.GenAIResponseIDKey,
108108
Value: attribute.StringValue(h.LLMGetter.GetAIResponseID(request, response)),
109109
}, attribute.KeyValue{
110-
Key: "gen_ai.response.model", //semconv.GenAIResponseModelKey,
110+
Key: semconv.GenAIResponseModelKey,
111111
Value: attribute.StringValue(h.LLMGetter.GetAIResponseModel(request, response)),
112112
}, attribute.KeyValue{
113-
Key: "gen_ai.usage.output_tokens", //semconv.GenAIUsageOutputTokensKey,
113+
Key: semconv.GenAIUsageOutputTokensKey,
114114
Value: attribute.Int64Value(h.LLMGetter.GetAIUsageOutputTokens(request, response)),
115115
}, attribute.KeyValue{
116-
Key: "gen_ai.response.id", //semconv.GenAIResponseIDKey,
116+
Key: semconv.GenAIResponseIDKey,
117117
Value: attribute.StringValue(h.LLMGetter.GetAIResponseID(request, response)),
118118
})
119119
return attributes, context

0 commit comments

Comments
 (0)