HiAgent Observe SDK
OpenTelemetry Trace
OpenTelemetry(OTel)是一个开源的、具备厂商中立性的可观测性框架。它提供了一组规范、API 和库,基于特定结构化数据建模,以输出应用程序的分布式追踪(Trace)、指标(Metrics)和日志(Log)数据。
HiAgent 支持接收来自 OpenTelemetry 客户端上报的 Trace 数据并可视化展示,从而实现对应用程序的深度监控和分析。
基于 OpenTelemetry 客户端上报的流程图如下所示:
OpenTelemetry Trace 集成方式
通过 OpenTelemetry SDK 上报 Trace,你可以使用各种语言的 OpenTelemetry SDK 将 Trace 数据上报到 HiAgent。通过 OpenTelemetry SDK 上报时,开发者需要直接在代码中引入 OpenTelemetry SDK 来创建和管理 Trace 数据(例如创建 Span、设置 Attribute、记录 Event 等)。这种方式需要开发者对 OpenTelemetry 的 SDK 有一定的了解,并在代码中明确实现埋点逻辑。
常见问题
HiAgent 支持什么协议?
HiAgent 不支持 GRPC 协议的 OpenTelemetry Endpoint,需使用 http/protobuf 协议。以 Python 为例,配置示例如下:
import os
import time
from dotenv import load_dotenv
from hiagent_observe import client
from opentelemetry import trace
load_dotenv()
if __name__ == "__main__":
try:
# 初始化 OpenTelemetry Client,并且注入鉴权的 header
# 鉴权的 header 每个小时会自动刷新
client.init(
# 配置为 HiAgent 的 OpenTelemetry Endpoint
trace_endpoint=os.getenv("HIAGENT_TRACE_ENDPOINT"),
# 配置为 HiAgent 的 Top Endpoint
top_endpoint=os.getenv("HIAGENT_TOP_ENDPOINT"),
product_code=os.getenv("HIAGENT_PRODUCT_CODE"),
# 配置为 HiAgent 的个人中心申请的 access key
ak=os.getenv("VOLC_ACCESSKEY"),
# 配置为 HiAgent 的个人中心申请的 secret key
sk=os.getenv("VOLC_SECRETKEY"),
# 配置为 HiAgent 的自定义应用的 workspace id
workspace_id=os.getenv("WORKSPACE_ID"),
# 配置为 HiAgent 的自定义应用的 app id
app_id=os.getenv("CUSTOM_APP_ID"),
)
except Exception as e:
raise RuntimeError(e)
tracer = trace.get_tracer("example-tracer") # 创建一个 Tracer
for i in range(100000):
with tracer.start_as_current_span("main-operation") as root_span:
with tracer.start_as_current_span("do-work") as span:
span.set_attributes(
{
"http.method": "GET",
"http.route": "/api/work",
"http.status_code": 200,
}
)
print("push trace")
time.sleep(2)
更完整的例子参考这里。
Metadata
Release files for hiagent-observe 3.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hiagent_observe-3.2.1.tar.gz | 159.4 kB | Without provenance | Details for hiagent_observe-3.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hiagent_observe-3.2.1-py3-none-any.whl | Python 3 | none | any | Details for hiagent_observe-3.2.1-py3-none-any.whl |
Total release size: 172.2 kB
Release files / hiagent_observe-3.2.1.tar.gz
| Download URL | hiagent_observe-3.2.1.tar.gz |
|---|---|
| Size | 159.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a0b216e0f17ab182fcaff38ed2d366b192a6fb0cdb01b3949f3b57e8073cc220
|
|
BLAKE2b-256 checksum How to use checksums |
ab20a67f25b679f862b39bea5a4230e2f594304aa33897df80fae5ed5651770e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Release files / hiagent_observe-3.2.1-py3-none-any.whl
| Download URL | hiagent_observe-3.2.1-py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f798f5e50d96c059dddb42e37950aedeceb02a4de461fb51df491435dfeb1221
|
|
BLAKE2b-256 checksum How to use checksums |
bdd4e7ef7ee875686ca1eb0a6693b1b984418887f371c2f55c94d65c5a122f68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Security for hiagent-observe 3.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.