汇报客户端执行结果时,上报traceId
This commit is contained in:
parent
2e0ca49839
commit
fd3ec697fb
|
@ -289,6 +289,21 @@ public class JobService
|
|||
task.Key = result.Key;
|
||||
task.Message = result.Message;
|
||||
|
||||
//var traceId = result.TraceId ?? DefaultSpan.Current + "";
|
||||
//if (!traceId.IsNullOrEmpty()) task.TraceId = traceId;
|
||||
//task.TraceId += $",{result.TraceId},{DefaultSpan.Current}";
|
||||
var tis = task.TraceId.Split(",", StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
var traceId = result.TraceId;
|
||||
if (!traceId.IsNullOrEmpty())
|
||||
{
|
||||
var ss = traceId.Split('-');
|
||||
if (ss.Length > 3 && ss[0].Length == 2) traceId = ss[1];
|
||||
if (!tis.Contains(traceId)) tis.Add(traceId);
|
||||
}
|
||||
traceId = DefaultSpan.Current?.TraceId;
|
||||
if (!traceId.IsNullOrEmpty() && !tis.Contains(traceId)) tis.Add(traceId);
|
||||
task.TraceId = tis.Join(",");
|
||||
|
||||
// 已终结的作业,汇总统计
|
||||
if (result.Status == JobStatus.完成 || result.Status == JobStatus.错误)
|
||||
{
|
||||
|
|
|
@ -63,6 +63,6 @@ public class Startup
|
|||
|
||||
// 启用星尘注册中心,向注册中心注册服务,服务消费者将自动更新服务端地址列表
|
||||
app.RegisterService("AntWeb", null, env.EnvironmentName);
|
||||
app.RegisterService("AntServer", null, env.EnvironmentName);
|
||||
//app.RegisterService("AntServer", null, env.EnvironmentName);
|
||||
}
|
||||
}
|
|
@ -31,6 +31,9 @@ public partial class TaskResult : ITaskResult
|
|||
/// <summary>最后键值</summary>
|
||||
public String Key { get; set; }
|
||||
|
||||
/// <summary>链路追踪</summary>
|
||||
public String TraceId { get; set; }
|
||||
|
||||
/// <summary>消息内容。异常信息或其它任务消息</summary>
|
||||
public String Message { get; set; }
|
||||
#endregion
|
||||
|
|
|
@ -136,16 +136,17 @@ public abstract class Handler : IExtend, ITracerFeature, ILogFeature
|
|||
{
|
||||
if (task == null) return;
|
||||
|
||||
var result = new TaskResult { ID = task.ID };
|
||||
var ctx = new JobContext
|
||||
{
|
||||
Handler = this,
|
||||
Task = task,
|
||||
Result = new TaskResult { ID = task.ID },
|
||||
Result = result,
|
||||
};
|
||||
|
||||
// APM埋点
|
||||
var span = Schedule.Tracer?.NewSpan($"job:{Name}", task.Data ?? $"({task.Time.ToFullString()}, {task.End.ToFullString()})");
|
||||
ctx.Remark = span?.ToString();
|
||||
result.TraceId = span?.ToString();
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
try
|
||||
|
|
|
@ -18,6 +18,8 @@ internal class HelloJob : Handler
|
|||
|
||||
protected override Int32 Execute(JobContext ctx)
|
||||
{
|
||||
using var span = Tracer?.NewSpan("HelloJob", ctx.Task.Time);
|
||||
|
||||
// 当前任务时间
|
||||
var time = ctx.Task.Time;
|
||||
WriteLog("新生命蚂蚁调度系统!当前任务时间:{0}", time);
|
||||
|
|
Loading…
Reference in New Issue