func zapLogWriteOnEnter()

in pkg/rules/zap/setup.go [38:64]


func zapLogWriteOnEnter(call api.CallContext, ce *zapcore.CheckedEntry, fields ...zap.Field) {
	if !zapEnabler.Enable() {
		return
	}
	var traceIdOk, spanIdOk bool
	if fields != nil {
		for _, v := range fields {
			if v.Key == "trace_id" {
				traceIdOk = true
			} else if v.Key == "span_id" {
				spanIdOk = true
			}
		}
	}
	if !traceIdOk {
		traceId, spanId := trace.GetTraceAndSpanId()
		if traceId != "" {
			fields = append(fields, zap.String("trace_id", traceId))
		}
		if spanId != "" && !spanIdOk {
			fields = append(fields, zap.String("span_id", spanId))
		}
		call.SetParam(1, fields)
	}

	return
}