# 本地代码监控 AutoGen 支持使用 [OpenTelemetry](https://opentelemetry.io) 对代码进行监控。这使您能够从代码中收集追踪记录和日志,并将其发送到您选择的后端。 调试时,您可以使用本地后端如 [Aspire](https://aspiredashboard.com/) 或 [Jaeger](https://www.jaegertracing.io/)。本指南将以 Aspire 为例进行说明。 ## 设置 Aspire 按照[此文档](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/dashboard/overview?tabs=bash#standalone-mode)的说明以独立模式设置 Aspire。这需要您的机器上已安装 Docker。 ## 代码监控配置 设置好仪表板后,接下来就是将追踪记录和日志发送到该仪表板。您可以按照[监控指南](../framework/telemetry.md)中的步骤来设置 OpenTelemetry SDK 和导出器。 当代码运行时,在 Aspire 仪表板运行的情况下对代码进行监控后,您应该能在仪表板中看到追踪记录和日志。 ## 使用 Open AI 观察 LLM 调用 如果您正在使用 Open AI 包,可以通过为该库设置 OpenTelemetry 来观察 LLM 调用。本示例中我们使用 [opentelemetry-instrumentation-openai](https://pypi.org/project/opentelemetry-instrumentation-openai/)。 安装包: ```bash pip install opentelemetry-instrumentation-openai ``` 启用监控: ```python from opentelemetry.instrumentation.openai import OpenAIInstrumentor OpenAIInstrumentor().instrument() ``` 现在运行您的代码将会将包括 LLM 调用在内的追踪记录发送到您的监控后端(本例中为 Aspire)。 ![Open AI 监控日志](../../../images/open-ai-telemetry-example.png)