如何使用 Spring Sleuth 2.0 记录 MDC? [英] How to log MDC with Spring Sleuth 2.0?

查看:64
本文介绍了如何使用 Spring Sleuth 2.0 记录 MDC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

参考如何用春季侦探?我认为这已经/将随着 spring-cloud 2.0 改变(d),因为不再有 SpanLoggerSlf4jSpanLogger(或者我找不到它)

referring to quesition/answer in How to log MDC with Spring Sleuth? I think this has/will change(d) with spring-cloud 2.0 as there is no SpanLogger or Slf4jSpanLogger anymore (or I don't find it)

如果应用程序属性 spring.sleuth.baggage-keysspring.sleuth.propagation-keys 如果设置也将放在 MDC I 中,那不是很好吗?在 Slf4jCurrentTraceContext 里面思考(因为这个类目前是 final 我不能子类化它)

Wouldn't it be nice if application properties spring.sleuth.baggage-keys and spring.sleuth.propagation-keys if set would also be put in MDC I think inside Slf4jCurrentTraceContext (as this class is currently final I cannot subclass it)

如果没有,我如何相应地使用 spring-cloud 2.0 实现这一点?

If not, how could I achieve this with spring-cloud 2.0 accordingly?

推荐答案

我们不想将所有条目都放在 MDC 中(这确实没有多大意义).但是,您可以复制 Slf4jCurrentTraceContext 并以您想要的方式扩展它(并将其注册为 bean),或者创建您自己的 CurrentTraceContext 实现来包装现有的 CurrentTraceContext 通过 Bean 后处理器并执行额外的逻辑.我想第一个选项更可取.

We don't want to put all entries in MDC (that really doesn't make a lot of sense). You can however either copy the Slf4jCurrentTraceContext and extend it in the way you want to (and register it as a bean) or maybe create your own implementation of CurrentTraceContext that would wrap the existing CurrentTraceContext via a Bean Post Processor and perform additional logic. I guess the first option is more preferable.

这篇关于如何使用 Spring Sleuth 2.0 记录 MDC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆