Skip to main content

CLS observability SDK for LangChain/LangGraph — 6-layer span hierarchy, direct upload to Tencent Cloud CLS

Project description

tencentcloud-cls-sdk-langchain

腾讯云 CLS(日志服务)LangChain/LangGraph 可观测插件。

自动采集 LangChain/LangGraph 应用的调用链路,生成 6 层 Span 层级模型,直接上报到 CLS。

安装

pip install tencentcloud-cls-sdk-langchain

插件不包含 LangChain/LangGraph 本身,如未安装请先:pip install langchain langgraph langchain-openai

快速接入

1. 配置 CLS 凭据(一次性)

python -m tencentcloud_cls_sdk_langchain.cls_config init

按提示输入 CLS 接入点、Topic ID、SecretId/SecretKey,配置保存到 .env

2. 代码接入

在应用启动代码中加入 3 行:

from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from tencentcloud_cls_sdk_langchain import LangChainInstrumentor
from tencentcloud_cls_sdk_langchain.cls_cloud_exporter import CLSCloudExporter

provider = TracerProvider()
provider.add_span_processor(BatchSpanProcessor(CLSCloudExporter()))
LangChainInstrumentor().instrument(tracer_provider=provider)

# 下面正常写你的 LangChain/LangGraph 代码,无需任何改动

3. 验证

运行应用后约 30 秒,到 CLS 控制台 → 日志主题 → 检索分析,应能看到 6 类 Span。

Span 层级模型

entry (应用入口)
 └─ session (对话窗口)
     └─ agent (每次提问)
         └─ step (每轮 ReAct)
             ├─ chat (LLM 调用)
             └─ tool (工具调用)

环境变量

配置命令 cls_config init 会自动写入 .env,也可以手动设置:

变量 必填 说明
CLS_ENDPOINT CLS API 接入点
CLS_TOPIC_ID CLS 日志主题 ID
CLS_SECRET_ID 腾讯云 SecretId
CLS_SECRET_KEY 腾讯云 SecretKey
CLS_SERVICE_NAME 服务名称(默认 langchain-app

License

Apache-2.0

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

tencentcloud_cls_sdk_langchain-1.0.2.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

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

tencentcloud_cls_sdk_langchain-1.0.2-py3-none-any.whl (28.1 kB view details)

Uploaded Python 3

File details

Details for the file tencentcloud_cls_sdk_langchain-1.0.2.tar.gz.

File metadata

File hashes

Hashes for tencentcloud_cls_sdk_langchain-1.0.2.tar.gz
Algorithm Hash digest
SHA256 7ae71faa69aecf22e2a1a67621f03b42ff1b048df50f4bc27acd986aa0bfc7e4
MD5 303c7af1e2a17b7e7f1a4682e0d598d0
BLAKE2b-256 8b718236d8e2789f8085c520ded53857a4c1050b19e4f8a2ebb52da95e6cb8e7

See more details on using hashes here.

File details

Details for the file tencentcloud_cls_sdk_langchain-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for tencentcloud_cls_sdk_langchain-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a786bdc4fcf7d0e5bfcbd4c4431af69ee7a73db2265cd2872901ec7b5048f120
MD5 ca53dbdf784b0fe11ec14046f3486af5
BLAKE2b-256 07c52b1a41fa58c978b0947edee31110e6213b7afe9329c7940c0359f8567850

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