我最近正在升级到Spring Cloud Sleuth 2.0.0,现在面临着从外部服务正确提取跟踪ID的问题。
有 ExternalService (不受我控制),该消息将消息发布到ActiveMQ队列中,该消息头的值为“ X-B3-TraceId”,这是一个16个字符的字符串,如“ 1234567890abcdef”。 / p>
我将从 MyService 中的队列中取出此消息,并带有JmsListener注释消息:
mvn dependency:tree
当我使用TracingChannelInterceptor从标题中获取traceId时,它将不会在日志输出中放入正确的ID。
// You need Maven installed to run it.
lazy val mavenDependencyTree = taskKey[Unit]("Prints a Maven dependency tree")
mavenDependencyTree := {
val scalaReleaseSuffix = "_" + scalaVersion.value.split('.').take(2).mkString(".")
val pomXml =
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>1.0</version>
<dependencies>
{
libraryDependencies.value.map(moduleId => {
val suffix = moduleId.crossVersion match {
case binary: sbt.librarymanagement.Binary => scalaReleaseSuffix
case _ => ""
}
<dependency>
<groupId>{moduleId.organization}</groupId>
<artifactId>{moduleId.name + suffix}</artifactId>
<version>{moduleId.revision}</version>
</dependency>
})
}
</dependencies>
</project>
val printer = new scala.xml.PrettyPrinter(160, 2)
val pomString = printer.format(pomXml)
val pomPath = java.nio.file.Files.createTempFile("", ".xml").toString
val pw = new java.io.PrintWriter(new File(pomPath))
pw.write(pomString)
pw.close()
println(s"Formed pom file: $pomPath")
import sys.process._
s"mvn -f $pomPath dependency:tree".!
}
我实际上期望这行。
...
/**
* Pulls the messages from the ActiveMQ server which are located in the destination queue.
*/
@JmsListener(destination = "${destination}")
void pullMessage(Message<String> msg) throws IOException {
String payload = msg.getPayload();
Span span = interceptor.nextSpan(message);
...
为什么Sleuth会修改该值,以及如何正确传播我的跟踪上下文以能够在两个系统之间跟踪消息?
在以前的Sleuth版本中,我使用此方法从标头中提取了traceId。
2018-07-01 21:59:10.529 INFO [MyService,fae6f4dac5903bb0,fae6f4dac5903bb0,false] 19276 --- [ main] ...
希望你能帮助我。