feat(tracing): 集成 OpenTelemetry 链路追踪功能

- 在 base.py 中添加文件下载、上传和 FFmpeg 执行的链路追踪
- 在 api_client.py 中实现 API 请求的链路追踪和错误标记
- 在 lease_service.py 中添加租约续期的链路追踪支持
- 在 task_executor.py 中集成任务执行的完整链路追踪
- 新增 util/tracing.py 工具模块提供统一的追踪上下文管理
- 在 .env.example 中添加 OTEL 配置选项
- 在 index.py 中初始化和关闭链路追踪功能
This commit is contained in:
2026-02-07 00:11:01 +08:00
parent c9a6133be9
commit 9b373dea34
8 changed files with 549 additions and 149 deletions

View File

@@ -34,6 +34,7 @@ from domain.config import WorkerConfig
from services.api_client import APIClientV2
from services.task_executor import TaskExecutor
from constant import SOFTWARE_VERSION
from util.tracing import initialize_tracing, shutdown_tracing
# 日志配置
def setup_logging():
@@ -113,6 +114,9 @@ class WorkerV2:
logger.error(f"Configuration error: {e}")
sys.exit(1)
tracing_enabled = initialize_tracing(self.config.worker_id, SOFTWARE_VERSION)
logger.info("OTel tracing %s", "enabled" if tracing_enabled else "disabled")
# 初始化 API 客户端
self.api_client = APIClientV2(self.config)
@@ -212,6 +216,7 @@ class WorkerV2:
# 关闭 API 客户端
self.api_client.close()
shutdown_tracing()
logger.info("Worker stopped")