使用插桩库
When you develop an app, you might use third-party libraries and frameworks to accelerate your work. If you then instrument your app using OpenTelemetry, you might want to avoid spending additional time to manually add traces, logs, and metrics to the third-party libraries and frameworks you use.
Many libraries and frameworks already support OpenTelemetry or are supported through OpenTelemetry instrumentation, so that they can generate telemetry you can export to an observability back end.
If you are instrumenting an app or service that use third-party libraries or frameworks, follow these instructions to learn how to use natively instrumented libraries and instrumentation libraries for your dependencies.
Use natively instrumented libraries
If a library comes with OpenTelemetry support by default, you can get traces, metrics, and logs emitted from that library by adding and setting up the OpenTelemetry SDK with your app.
The library might require some additional configuration for the instrumentation. Go to the documentation for that library to learn more.
As of today, we don’t know about any Go library that has OpenTelemetry natively integrated. If you know about such a library, let us know.
使用插桩库
如果某个库本身没有集成 OpenTelemetry,你可以使用 插桩库(instrumentation libraries) 为这个库或者框架生成遥测数据。
例如,
net/http
的插桩库
会基于 HTTP 请求自动创建 span 和
metrics。
安装
每个插桩库是一个独立的 Go 包。通常你需要使用 go get
获取相应的包。例如,如果要安装由
Contrib repository
维护的插桩库,可以运行以下命令:
go get go.opentelemetry.io/contrib/instrumentation/{import-path}/otel{package-name}
然后根据库的要求在代码中配置它。
Getting Started 中展示了如何为一个 net/http
服务器设置插桩。
可用插桩库
完整的可用插桩库列表见 OpenTelemetry 支持库列表.
后续步骤
插桩库可以生成入站和出站 HTTP 请求的遥测数据,但不会对你的实际应用程序进行插桩。
你可以通过在代码中集成自定义插桩来丰富你的遥感数据。 这补充了标准库生成的遥测数据,并且可以让你更深入地了解正在运行的应用程序。
Feedback
Was this page helpful?
Thank you. Your feedback is appreciated!
Please let us know how we can improve this page. Your feedback is appreciated!