Skip to content

Commit

Permalink
调整字段
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Dec 27, 2023
1 parent a518895 commit f4fece3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions driver/clickhouse/saveTraceContextConsumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions traceManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
},
Expand All @@ -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,
},
}
Expand All @@ -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,
Expand All @@ -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,
},
}
Expand Down
32 changes: 16 additions & 16 deletions trackContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

type TraceContext struct {
TraceId int64 `es:"primaryKey"` // 上下文ID
TraceId int64 // 上下文ID
AppId int64 // 应用ID
AppName string // 应用名称
AppIp string // 应用IP
Expand All @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit f4fece3

Please sign in to comment.