spring-cloud/spring-cloud-sleuth

java.lang.IllegalStateException: Missing: traceId with AWS propagation type

BenitoVisone opened this issue · 5 comments

Describe the bug

Environment setup:

  • JDK: Java 11.0.17
  • Spring Boot: 2.7.13
  • Spring Cloud: 2021.0.8
  • Spring Cloud Starter Sleuth: 3.1.9
  • Brave: 5.13.9
  • Zipkin-aws: 0.21.3

In our application we use Spring Cloud Sleuth for tracing in our micro-services. We set propagation type to AWS because our architecture is based on this Cloud Provider.

The problem we are facing is the following: When we receive an X-Amzn-Trace-Id header with the following format: Root=1-1373cbb-37f4b48ed7ff3eebbd62b5e01 the application crashes with the Exception java.lang.IllegalStateException: Missing: traceId from the brave.propagation package during the trace id extraction.

Based on this AWS Documentation, the X-Amzn-Trace-Id header consists of three numbers separated by hyphens version-time-id , where the time field should be of 8 hexadecimal digits.

The problem seems related to the time(1373cbb, 7 characters) format, when its length is different from 8. In fact, in this section of code we can see that if the timestamp length is different from 8 the traceId is never initialised, causing the Exception.

This is the only case that throws this unhandled Exception, in other cases, such as invalid hexadecimal digits, the application correctly generates a new trace id without propagating the malformed one.

Is this working as intended?

Sample

In order to test this behaviour you need to set sleuth.propagation.type property to AWS and try to send a request with the header X-Amzn-Trace-Id: Root=1-1373cbb-37f4b48ed7ff3eebbd62b5e01 which cause the Exception being thrown.

Can you provide the full stack trace?

this is the full stack trace:

java.lang.IllegalStateException: Missing: traceId
	at brave.propagation.TraceIdContext$Builder.build(TraceIdContext.java:131)
	at brave.propagation.aws.AWSExtractor.extract(AWSExtractor.java:189)
	at org.springframework.cloud.sleuth.brave.bridge.CompositePropagationFactory.lambda$extractor$3(CompositePropagationFactorySupplier.java:122)
	at brave.http.HttpServerHandler.handleReceive(HttpServerHandler.java:111)
	at org.springframework.cloud.sleuth.brave.bridge.BraveHttpServerHandler.handleReceive(BraveHttpServerHandler.java:41)
	at org.springframework.cloud.sleuth.instrument.web.tomcat.TraceValve.invoke(TraceValve.java:90)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:390)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:926)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1791)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.base/java.lang.Thread.run(Thread.java:834)

I think you should file the issue in Brave aws propagation module. We merely delegate work to their code.

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.