本文介绍了在Springboot中添加trace.id和transaction.id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Springboot微服务.对于日志记录,我使用的是Elastic通用方案,该方案使用实现ecs-logging-java .

I have a Springboot micro-service. For logging I'm using Elastic common scheme, implemented using ecs-logging-java.

我想设置trace.ID和transaction.ID,但是我不确定如何设置?

I want to set the trace.ID and a transaction.ID but I'm not sure how?

奖金问题,我想的是trace.ID应该是通过多个系统遵循请求的ID. transaction.ID仅用于服务内吗?

Bonus question, I'm I right in thinking trace.ID should be the ID to following the request through multiple system. transaction.ID is just for within the service?

推荐答案

按如下所示配置您的日志记录模式

Configure your logging patter as below

<pattern> %d{yyyy-MM-dd HH:mm:ss.SSS} %thread [%X{trace-id}] [%-5level] %class{0} - %msg%n </pattern>

在MDC中放入跟踪ID. (MDC属于特定的线程上下文)

Put trace Id in MDC. (MDC belongs to particular thread context)

  `MDC.put("trace-id", "traceid1");`

因此,只要您的日志将打印一条消息,它就会打印跟踪ID.请遵循以下artical. http://logback.qos.ch/manual/mdc.html

So whenever your log will print a message, it will print trace id.Follow below artical.http://logback.qos.ch/manual/mdc.html

这篇关于在Springboot中添加trace.id和transaction.id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 19:37
查看更多