Skip to main content

HiAgent Observe SDK

Project description

HiAgent Observe SDK

OpenTelemetry Trace

OpenTelemetry(OTel)是一个开源的、具备厂商中立性的可观测性框架。它提供了一组规范、API 和库,基于特定结构化数据建模,以输出应用程序的分布式追踪(Trace)、指标(Metrics)和日志(Log)数据。​ HiAgent 支持接收来自 OpenTelemetry 客户端上报的 Trace 数据并可视化展示,从而实现对应用程序的深度监控和分析。​ 基于 OpenTelemetry 客户端上报的流程图如下所示:​ ​ observe

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"),
      # 配置为 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)

更完整的例子参考这里

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hiagent_observe-2.0.1.tar.gz (153.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hiagent_observe-2.0.1-py3-none-any.whl (159.9 kB view details)

Uploaded Python 3

File details

Details for the file hiagent_observe-2.0.1.tar.gz.

File metadata

  • Download URL: hiagent_observe-2.0.1.tar.gz
  • Upload date:
  • Size: 153.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for hiagent_observe-2.0.1.tar.gz
Algorithm Hash digest
SHA256 6fb8e7f8e6bc198e87b9a53bbf30b4f4a3aa13097ecd4f86c0c3a83c0caecce3
MD5 bde19d5c1bbe2a4044fede5e7f43bb5b
BLAKE2b-256 124061056bcd218afc9239379b0ef618c11673bb998f5ec8a08823d386d73e3e

See more details on using hashes here.

File details

Details for the file hiagent_observe-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: hiagent_observe-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 159.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for hiagent_observe-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 029b3ecd0ed5d12ccba2fc332e562a77b187155468767adf7aafc4d3c4beba11
MD5 3700751d83b4a0c0c4e3c5982948f7f6
BLAKE2b-256 8f2977690a8401e1cc8b7c35c5d6972e54a6416df5c586ab508e2eed875a4a3f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page