Skip to content

Commit

Permalink
修复:Enable未启用时,无法打印日志
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Nov 14, 2023
1 parent 8b51351 commit 530828b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package linkTrace

type config struct {
Enable bool
PrintLog bool
Enable bool // 上传链路日志
PrintLog bool // 打印链路日志
}
7 changes: 5 additions & 2 deletions module.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func (module Module) PreInitialize() {
}

func (module Module) PostInitialize() {
initEsContext()
queue.Subscribe("TraceContext", "SaveTraceContext", 1000, saveTraceContextConsumer)
// 启用了链路追踪后,才需要初始化ES和消费
if defConfig.Enable {
initEsContext()
queue.Subscribe("TraceContext", "SaveTraceContext", 1000, saveTraceContextConsumer)
}
}
2 changes: 1 addition & 1 deletion traceManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func newTraceDetail(callType eumCallType.Enum, methodName string) trace.BaseTrac
}

func add(traceDetail trace.ITraceDetail) {
if t := trace.CurTraceContext.Get(); t != nil && defConfig.Enable {
if t := trace.CurTraceContext.Get(); t != nil {
detail := traceDetail.GetTraceDetail()
// 时间轴:上下文入口起点时间到本次开始时间
detail.Timeline = time.Duration(detail.StartTs-t.GetStartTs()) * time.Microsecond
Expand Down

0 comments on commit 530828b

Please sign in to comment.