-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
fix: Logging middleware will be missing trace_id when logger is filterlogger #2571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Logging middleware will be missing trace_id when logger is filterlogger #2571
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2571 +/- ##
==========================================
- Coverage 85.18% 85.15% -0.03%
==========================================
Files 88 88
Lines 3840 3846 +6
==========================================
+ Hits 3271 3275 +4
- Misses 396 397 +1
- Partials 173 174 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@Cynicism-zx please fix lint failed |
@shenqidebaozi fixed |
f, ok := l.(*Filter) | ||
if ok { | ||
lg, ok := f.logger.(*logger) | ||
if ok { | ||
return &logger{logger: lg.logger, prefix: lg.prefix, hasValuer: lg.hasValuer, ctx: ctx} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest to replace the if !ok {...}
block with something like the following to be able to handle nested Filters:
for {
if f, ok := l.(*Filter); ok {
l = f.logger
} else {
break
}
}
c, ok = l.(*logger)
if !ok {
return &logger{logger: l, ctx: ctx}
}
@Cynicism-zx @shenqidebaozi Could you please comment? |
don't simple to using origin logger, It will cause the Filter not working. |
fix logging middle don't get trace_id value when logger is filterLogger Which issue(s) this PR fixes (resolves / be part of): go-kratos#2570 go-kratos#2571
Description (what this PR does / why we need it):
修复启用链路追逐后log中间件使用logfilter后,打印的请求日志中缺失trace.id值,如下
Which issue(s) this PR fixes (resolves / be part of):
fix/logfilter #2570
Other special notes for the reviewers:
应该在log.WithContext()方法中进一步断言logger类型,并取出初始logger的prefix