Skip to content

Commit

Permalink
添加链路追踪忽略标记
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Oct 20, 2023
1 parent fb273f9 commit daaac14
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions saveTraceContextConsumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

// 写入到ES
func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListAny, remainingCount int) {
curTraceContext.Get().Ignore()
lstTraceContext := collections.NewList[TraceContext]()
lstMessage.Foreach(func(item *any) {
traceContext := *item
Expand Down
12 changes: 11 additions & 1 deletion trackContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type TraceContext struct {
List collections.List[trace.ITraceDetail] `es_type:"object"` // 调用的上下文
IsException bool // 是否执行异常
ExceptionMessage string // 异常信息
ignore bool // 忽略这次的链路追踪
Web WebContext
Consumer ConsumerContext
Task TaskContext
Expand Down Expand Up @@ -73,9 +74,15 @@ func (receiver *TraceContext) GetStartTs() int64 {

// End 结束当前链路
func (receiver *TraceContext) End() {
if receiver.ignore {
return
}
receiver.EndTs = time.Now().UnixMicro()
receiver.UseTs = time.Duration(receiver.EndTs-receiver.StartTs) * time.Microsecond

// 移除忽略的明细
receiver.List.RemoveAll(func(item trace.ITraceDetail) bool {
return item.GetTraceDetail().IsIgnore()
})
// 启用了链路追踪后,把数据写入到本地队列中
if defConfig.Enable {
queue.Push("TraceContext", *receiver)
Expand All @@ -84,6 +91,9 @@ func (receiver *TraceContext) End() {
// 打印日志
receiver.printLog()
}
func (receiver *TraceContext) Ignore() {
receiver.ignore = true
}

// GetList 获取链路明细
func (receiver *TraceContext) GetList() collections.List[trace.ITraceDetail] {
Expand Down

0 comments on commit daaac14

Please sign in to comment.