diff --git a/driver/clickhouse/saveTraceContextConsumer.go b/driver/clickhouse/saveTraceContextConsumer.go index 57c27c9..2a0983c 100644 --- a/driver/clickhouse/saveTraceContextConsumer.go +++ b/driver/clickhouse/saveTraceContextConsumer.go @@ -25,10 +25,10 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA traceContext := (*item).(linkTrace.TraceContext) po := mapper.Single[TraceContextPO](traceContext) // mapper组件不支持嵌入类型转换,先手动处理。 - po.WebContextPO = mapper.Single[WebContextPO](traceContext.Web) - po.TaskContextPO = mapper.Single[TaskContextPO](traceContext.Task) - po.ConsumerContextPO = mapper.Single[ConsumerContextPO](traceContext.Consumer) - po.WatchKeyContextPO = mapper.Single[WatchKeyContextPO](traceContext.WatchKey) + //po.WebContextPO = mapper.Single[WebContextPO](traceContext.WebContext) + //po.TaskContextPO = mapper.Single[TaskContextPO](traceContext.TaskContext) + //po.ConsumerContextPO = mapper.Single[ConsumerContextPO](traceContext.ConsumerContext) + //po.WatchKeyContextPO = mapper.Single[WatchKeyContextPO](traceContext.WatchKey) if !traceContext.Exception.IsNil() { exceptionStackPO := mapper.Single[ExceptionStackPO](traceContext.Exception) po.Exception = &exceptionStackPO diff --git a/traceManager.go b/traceManager.go index 0d32d32..8a572d0 100644 --- a/traceManager.go +++ b/traceManager.go @@ -34,7 +34,7 @@ func (*traceManager) EntryWebApi(domain string, path string, method string, cont TraceId: traceId, StartTs: time.Now().UnixMicro(), TraceType: eumTraceType.WebApi, - Web: WebContext{ + WebContext: WebContext{ WebDomain: domain, WebPath: path, WebMethod: method, @@ -134,7 +134,7 @@ func (*traceManager) EntryMqConsumer(server string, queueName string, routingKey TraceId: traceId, StartTs: time.Now().UnixMicro(), TraceType: eumTraceType.MqConsumer, - Consumer: ConsumerContext{ + ConsumerContext: ConsumerContext{ ConsumerServer: server, ConsumerQueueName: queueName, ConsumerRoutingKey: routingKey, @@ -156,7 +156,7 @@ func (*traceManager) EntryQueueConsumer(subscribeName string) trace.ITraceContex TraceId: traceId, StartTs: time.Now().UnixMicro(), TraceType: eumTraceType.QueueConsumer, - Consumer: ConsumerContext{ + ConsumerContext: ConsumerContext{ ConsumerServer: fmt.Sprintf("%s/%s/%v", fs.AppName, fs.AppIp, fs.AppId), ConsumerQueueName: subscribeName, }, @@ -177,7 +177,7 @@ func (*traceManager) EntryTask(taskName string) trace.ITraceContext { TraceId: traceId, StartTs: time.Now().UnixMicro(), TraceType: eumTraceType.Task, - Task: TaskContext{ + TaskContext: TaskContext{ TaskName: taskName, }, } @@ -197,7 +197,7 @@ func (*traceManager) EntryFSchedule(taskGroupName string, taskGroupId int64, tas TraceId: traceId, StartTs: time.Now().UnixMicro(), TraceType: eumTraceType.FSchedule, - Task: TaskContext{ + TaskContext: TaskContext{ TaskName: taskGroupName, TaskGroupId: taskGroupId, TaskId: taskId, @@ -219,7 +219,7 @@ func (*traceManager) EntryWatchKey(key string) trace.ITraceContext { TraceId: traceId, StartTs: time.Now().UnixMicro(), TraceType: eumTraceType.WatchKey, - WatchKey: WatchKeyContext{ + WatchKeyContext: WatchKeyContext{ WatchKey: key, }, } diff --git a/trackContext.go b/trackContext.go index 4a9aab1..e3e6299 100644 --- a/trackContext.go +++ b/trackContext.go @@ -13,7 +13,7 @@ import ( ) type TraceContext struct { - TraceId int64 `es:"primaryKey"` // 上下文ID + TraceId int64 // 上下文ID AppId int64 // 应用ID AppName string // 应用名称 AppIp string // 应用IP @@ -22,24 +22,24 @@ type TraceContext struct { EndTs int64 // 调用结束时间戳(微秒) UseTs time.Duration // 总共使用时间微秒 TraceType eumTraceType.Enum // 状态码 - List []trace.ITraceDetail `es_type:"object"` // 调用的上下文 + List []trace.ITraceDetail // 调用的上下文 ignore bool // 忽略这次的链路追踪 Exception trace.ExceptionStack // 异常信息 - Web WebContext - Consumer ConsumerContext - Task TaskContext - WatchKey WatchKeyContext + WebContext + ConsumerContext + TaskContext + WatchKeyContext } type WebContext struct { WebDomain string // 请求域名 - WebPath string `es_type:"text"` // 请求地址 + WebPath string // 请求地址 WebMethod string // 请求方式 WebContentType string // 请求内容类型 WebStatusCode int // 状态码 - WebHeaders collections.Dictionary[string, string] `es_type:"flattened" gorm:"json;not null;comment:请求头部"` - WebRequestBody string `es_type:"text"` // 请求参数 - WebResponseBody string `es_type:"text"` // 输出参数 + WebHeaders collections.Dictionary[string, string] // 请求头部 + WebRequestBody string // 请求参数 + WebResponseBody string // 输出参数 WebRequestIp string // 客户端IP } @@ -76,9 +76,9 @@ func (receiver WatchKeyContext) IsNil() bool { } func (receiver *TraceContext) SetBody(requestBody string, statusCode int, responseBody string) { - receiver.Web.WebRequestBody = requestBody - receiver.Web.WebStatusCode = statusCode - receiver.Web.WebResponseBody = responseBody + receiver.WebContext.WebRequestBody = requestBody + receiver.WebContext.WebStatusCode = statusCode + receiver.WebContext.WebResponseBody = responseBody } func (receiver *TraceContext) GetTraceId() int64 { @@ -151,11 +151,11 @@ func (receiver *TraceContext) printLog() { logs := strings.Join(lst.ToArray(), "\n") switch receiver.TraceType { case eumTraceType.WebApi: - flog.Printf("【%s链路追踪】TraceId:%s,耗时:%s,%s\n%s\n", receiver.TraceType.ToString(), flog.Green(parse.ToString(receiver.TraceId)), flog.Red(receiver.UseTs.String()), receiver.Web.WebPath, logs) + flog.Printf("【%s链路追踪】TraceId:%s,耗时:%s,%s\n%s\n", receiver.TraceType.ToString(), flog.Green(parse.ToString(receiver.TraceId)), flog.Red(receiver.UseTs.String()), receiver.WebContext.WebPath, logs) case eumTraceType.MqConsumer, eumTraceType.QueueConsumer: - flog.Printf("【%s链路追踪】TraceId:%s,耗时:%s,%s\n%s\n", receiver.TraceType.ToString(), flog.Green(parse.ToString(receiver.TraceId)), flog.Red(receiver.UseTs.String()), receiver.Consumer.ConsumerQueueName, logs) + flog.Printf("【%s链路追踪】TraceId:%s,耗时:%s,%s\n%s\n", receiver.TraceType.ToString(), flog.Green(parse.ToString(receiver.TraceId)), flog.Red(receiver.UseTs.String()), receiver.ConsumerContext.ConsumerQueueName, logs) case eumTraceType.Task, eumTraceType.FSchedule: - flog.Printf("【%s链路追踪】TraceId:%s,耗时:%s,%s\n%s\n", receiver.TraceType.ToString(), flog.Green(parse.ToString(receiver.TraceId)), flog.Red(receiver.UseTs.String()), receiver.Task.TaskName, logs) + flog.Printf("【%s链路追踪】TraceId:%s,耗时:%s,%s\n%s\n", receiver.TraceType.ToString(), flog.Green(parse.ToString(receiver.TraceId)), flog.Red(receiver.UseTs.String()), receiver.TaskContext.TaskName, logs) default: flog.Printf("【%s链路追踪】TraceId:%s,耗时:%s\n%s\n", receiver.TraceType.ToString(), flog.Green(parse.ToString(receiver.TraceId)), flog.Red(receiver.UseTs.String()), logs) }