Skip to content

Commit

Permalink
新增:etcd的链路追踪入口
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Oct 19, 2023
1 parent bf598f7 commit fb273f9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions eumTraceType/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ const (
QueueConsumer // 本地消费
FSchedule // 调度中心
Task // 本地任务
WatchKey // ETCD
)
22 changes: 21 additions & 1 deletion traceManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (*traceManager) EntryFSchedule(taskGroupName string, taskGroupId int64, tas
ParentAppName: "",
TraceId: traceId,
StartTs: time.Now().UnixMicro(),
TraceType: eumTraceType.Task,
TraceType: eumTraceType.FSchedule,
Task: TaskContext{
TaskName: taskGroupName,
TaskGroupId: taskGroupId,
Expand All @@ -207,6 +207,26 @@ func (*traceManager) EntryFSchedule(taskGroupName string, taskGroupId int64, tas
return context
}

// EntryWatchKey 创建etcd入口
func (*traceManager) EntryWatchKey(key string) trace.ITraceContext {
traceId := snowflake.GenerateId()
context := &TraceContext{
AppId: fs.AppId,
AppName: fs.AppName,
AppIp: fs.AppIp,
ParentAppName: "",
TraceId: traceId,
StartTs: time.Now().UnixMicro(),
TraceType: eumTraceType.WatchKey,
WatchKey: WatchKeyContext{
Key: key,
},
List: collections.NewList[trace.ITraceDetail](),
}
curTraceContext.Set(context)
return context
}

// TraceMq open、create埋点
func (*traceManager) TraceMq(method string, server string, exchange string) trace.ITraceDetail {
detail := &TraceDetailMq{
Expand Down
4 changes: 4 additions & 0 deletions trackContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type TraceContext struct {
Web WebContext
Consumer ConsumerContext
Task TaskContext
WatchKey WatchKeyContext
}

type WebContext struct {
Expand All @@ -52,6 +53,9 @@ type TaskContext struct {
TaskGroupId int64
TaskId int64
}
type WatchKeyContext struct {
Key string
}

func (receiver *TraceContext) SetBody(requestBody string, statusCode int, responseBody string) {
receiver.Web.RequestBody = requestBody
Expand Down

0 comments on commit fb273f9

Please sign in to comment.