kratos icon indicating copy to clipboard operation
kratos copied to clipboard

fix: Logging middleware will be missing trace_id when logger is filterlogger

Open LuoWeiJun-cynicism opened this issue 2 years ago • 3 comments

Description (what this PR does / why we need it):

修复启用链路追逐后log中间件使用logfilter后,打印的请求日志中缺失trace.id值,如下

INFO ts=2022-12-08T15:46:40+08:00 caller=log/log.go:30 trace.id= kind=server component=grpc operation=/video.basics.v1.notification.NotificationSrv/GetNotification args=webmaster_id:1595665043859443712 limit:20 code=0 reason= stack= latency=0.000850499

Which issue(s) this PR fixes (resolves / be part of):

fix/logfilter #2570

Other special notes for the reviewers:

应该在log.WithContext()方法中进一步断言logger类型,并取出初始logger的prefix

LuoWeiJun-cynicism avatar Dec 08 '22 08:12 LuoWeiJun-cynicism

Codecov Report

Merging #2571 (dc60dfd) into main (33d51a8) will decrease coverage by 0.02%. The diff coverage is 60.00%.

@@            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     
Impacted Files Coverage Δ
log/log.go 88.57% <60.00%> (-4.77%) :arrow_down:
transport/http/codec.go 60.37% <0.00%> (+0.76%) :arrow_up:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov-commenter avatar Jan 01 '23 12:01 codecov-commenter

@Cynicism-zx please fix lint failed

shenqidebaozi avatar Jan 09 '23 13:01 shenqidebaozi

@shenqidebaozi fixed

LuoWeiJun-cynicism avatar Jan 12 '23 06:01 LuoWeiJun-cynicism

@Cynicism-zx @shenqidebaozi Could you please comment?

stonelgh avatar Mar 15 '23 11:03 stonelgh

don't simple to using origin logger, It will cause the Filter not working.

freezeChen avatar Jun 15 '23 07:06 freezeChen