telemetry埋点

This commit is contained in:
Jerry Yan 2025-04-13 11:55:01 +08:00
parent 4f47689253
commit 91bb5e4e5a
2 changed files with 11 additions and 5 deletions

View File

@ -18,11 +18,16 @@ import (
var tracer = otel.Tracer("task")
func HandleTask(ctx context.Context, device config.DeviceMapping, task dto.Task) (*dto.FileObject, error) {
_, span := tracer.Start(ctx, "startTask")
subCtx, span := tracer.Start(ctx, "startTask")
defer span.End()
adapter := fs.GetAdapter()
span.SetAttributes()
span.SetAttributes(attribute.String("taskId", task.TaskID))
span.SetAttributes(attribute.String("startTime", task.StartTime.Format("2006-01-02 15:04:05")))
span.SetAttributes(attribute.String("endTime", task.EndTime.Format("2006-01-02 15:04:05")))
span.SetAttributes(attribute.String("device.no", device.DeviceNo))
span.SetAttributes(attribute.String("device.name", device.Name))
fileList, err := adapter.GetFileList(
ctx,
subCtx,
path.Join(device.Name, task.StartTime.Format("2006"+config.Config.FileName.DateSeparator+"01"+config.Config.FileName.DateSeparator+"02")),
task.StartTime,
)
@ -38,14 +43,14 @@ func HandleTask(ctx context.Context, device config.DeviceMapping, task dto.Task)
return nil, fmt.Errorf("没有找到文件")
}
span.SetAttributes(attribute.Int("fileCount", len(files)))
constructTask, err := util.CheckFileCoverageAndConstructTask(ctx, files, task.StartTime, task.EndTime, task)
constructTask, err := util.CheckFileCoverageAndConstructTask(subCtx, files, task.StartTime, task.EndTime, task)
if err != nil {
span.SetAttributes(attribute.String("error", err.Error()))
span.SetStatus(codes.Error, "文件片段检查失败")
log.Printf("文件片段检查失败, DeviceNo: %s, 错误: %v\n", device.DeviceNo, err)
return nil, err
}
ok := util.RunFfmpegTask(ctx, constructTask)
ok := util.RunFfmpegTask(subCtx, constructTask)
if !ok {
span.SetAttributes(attribute.String("error", "ffmpeg任务执行失败"))
span.SetStatus(codes.Error, "ffmpeg任务执行失败")

View File

@ -19,6 +19,7 @@ var tracer = otel.Tracer("vpt")
func startTask(device config.DeviceMapping, task dto.Task) {
ctx, span := tracer.Start(context.Background(), "startTask")
defer span.End()
span.SetAttributes(attribute.String("deviceNo", device.DeviceNo))
span.SetAttributes(attribute.String("taskId", task.TaskID))
span.SetAttributes(attribute.String("scenicId", task.ScenicID))