diff --git a/core/task.go b/core/task.go index 7c12992..25c6e58 100644 --- a/core/task.go +++ b/core/task.go @@ -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任务执行失败") diff --git a/main.go b/main.go index e894079..172c7e8 100644 --- a/main.go +++ b/main.go @@ -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))