Sleuth TraceId IllegalArgumentException Exception - spring-boot

Encountering the below exception, when using Sleuth along with Spring Boot
The Stack trace is as follows :
ZipkinHttpSpanExtractor.joinTrace 51 : Exception occurred while trying to extract span from carrier java.lang.IllegalArgumentException: Can't convert empty hex string to long at org.springframework.util.Assert.hasText(Assert.java:181) at org.springframework.cloud.sleuth.Span.hexToId(Span.java:583) at org.springframework.cloud.sleuth.instrument.web.ZipkinHttpSpanExtractor.buildParentSpan(ZipkinHttpSpanExtractor.java:91) at org.springframework.cloud.sleuth.instrument.web.ZipkinHttpSpanExtractor.joinTrace(ZipkinHttpSpanExtractor.java:49) at org.springframework.cloud.sleuth.instrument.web.ZipkinHttpSpanExtractor.joinTrace(ZipkinHttpSpanExtractor.java:19)
Using Sprint Boot version is 1.5.3 and spring-cloud-sleuth-core/1.3.1
Any pointers on the fix would be helpful... Thanks in advance.

Related

Netty doesn't allow pipe symbol | and throws Exception

My Endpoint is /mz/api/mot/pol/re/pt?Output=1|920222|R1205200130|Success|
I am using a Gateway application on Spring Boot which runs on Netty
and facing below exception,
java.lang.IllegalArgumentException: Illegal character in query at index 46:
at java.net.URI.create(URI.java:852) ~[na:1.8.0_242]
at reactor.netty.http.HttpOperations.resolvePath(HttpOperations.java:300) ~[reactor-netty-0.9.4.RELEASE.jar:0.9.4.RELEASE]
at reactor.netty.http.server.HttpServerOperations.<init>(HttpServerOperations.java:128) ~[reactor-netty-0.9.4.RELEASE.jar:0.9.4.RELEASE]
at reactor.netty.http.server.HttpTrafficHandler.channelRead(HttpTrafficHandler.java:157) ~[reactor-netty-0.9.4.RELEASE.jar:0.9.4.RELEASE]
at
The same error happens in Tomcat also and I solved it by setting relaxedQueryChars property. Kindly suggest how to do this. Thanks in advance.
You'll have to encode the pipes in your query string for netty. The "|" will become %7C
So this: /mz/api/mot/pol/re/pt?Output=1%7C920222%7CR1205200130%7CSuccess
Becomes: `/mz/api/mot/pol/re/pt?Output=1%7C920222%7CR1205200130%7CSuccess
There are lots of tools that will URL encode that string for you if you have control over the client side.
See also:
https://docs.oracle.com/javase/8/docs/api/java/net/URLEncoder.html

Zipkin With Spring Boot

I am using spring boot and zipkin.
And using spring slueth to generate trace Id.
Is there a way I can generate this trace Id on my own?
Also I want to log only specific requests say with 500 error or response time > threshold, how to do this?
To log only request with particular error you can add the log in your exception mapper where you are handling those error.
To show the log for error response you can set like below,
#Autowired
private Tracer tracer;
and set
tracer.addTag("error","Your message")

About map properties to java class in spring boot 2

I want to convert properties to map, see below
field2ZhNameMap.platform=平台
==>
private Map<String,String> field2ZhNameMap;
In Spring boot 1.5.6 start the app in tomcat it's OK, but use sprint boot 2.0.0.M7 start the app in tomcat I got below error
Caused by: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under '' to com.foo.bar.util.Field2ZhNameProperties
at org.springframework.boot.context.properties.bind.Binder.handleBindError(Binder.java:227)
Caused by: java.lang.IllegalArgumentException: PropertyName must not be empty
at org.springframework.util.Assert.hasLength(Assert.java:233)
at org.springframework.boot.origin.PropertySourceOrigin.<init>(PropertySourceOrigin.java:41)
After debuging source code I found start the app in tomcat it has a JndiPropertySource which caused above problem. So I have to explicitly disable JndiPropertySource by specify spring.jndi.ignore=true in a spring.properties to solve this problem.
In addition I found these classes like Binder do not exist in 1.5.6, it seems it has a big change from 1.5.6 to 2.0.0. So I want to know if has some documents record these change and guide how to correctly map properties to java class in spring boot 2?
For me, upgrade to Spring Boot 2.0.1.RELEASE on Tomcat 8.5.30 resolved PropertyName must not be empty

Spring cloud sleuth dependencies throwing RibbonLoadBalancerClientException in Spring boot stack application

We are planning to integrate spring sleuth in our Spring cloud microservices application. However when a Service A makes a call to Service B using RestTemplate we are getting RibbonLoadBalancerClient exception. Please find the stack trace below.
ResponseObject genericResponse = restTemplate.exchange(expandedUrl, HttpMethod.GET, new HttpEntity<>(null), ResponseObject.class).getBody();
Logger.log(DEBUG, "getDetails returned {} ", response);
return genericResponse.getData().getInformation();
The version are are using is as below
Spring Boot : springBootVersion = '1.5.3.RELEASE'
Spring Sleuth : spring-cloud-starter-sleuth:1.2.4.RELEASE
Spring cloud dependencies : spring-cloud-services dependencies:1.2.0.RELEASE,
spring-cloud-dependencies:Brixton.RELEASE
Exception - stacktrace :
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.AbstractMethodError: org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(Ljava/lang/String;Lorg/springframework/cloud/client/ServiceInstance;Lorg/springframework/cloud/client/loadbalancer/LoadBalancerRequest;)Ljava/lang/Object;| at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:978)| at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)| at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)|
You should be using the release train to manage versions. Also Brixton is a very old release train. Please upgrade and don't set library versions manually.

IllegalStateException in ExposeInvocationInterceptor after upgrading to Spring 4.1.x

After upgrading to Spring 4.1.4 and Spring Data Jpa 1.7.1 (from 4.0.2 and 1.5.1, respectively) I started to get IllegalStateException from ExposeInvocationInterceptor#currentInvocation()
At first I thought it could be somehow related to the following fix https://jira.spring.io/browse/SPR-12351 but I got the same exceptions also with Spring 4.1.1.
Any ideas what could be the problem?
Below is an excerpt from the exception stack trace:
java.lang.IllegalStateException: No MethodInvocation found: Check that an AOP invocation is in progress, and that the ExposeInvocationInterceptor is upfront in the interceptor chain. Specifically, note that advices with order HIGHEST_PRECEDENCE will execute before ExposeInvocationInterceptor!
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.currentInvocation(ExposeInvocationInterceptor.java:73)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$ThreadBoundTargetSource.createObject(CrudMethodMetadataPostProcessor.java:226)
at org.springframework.aop.target.AbstractLazyCreationTargetSource.getTarget(AbstractLazyCreationTargetSource.java:86)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:187)
at com.sun.proxy.$Proxy112.getLockModeType(Unknown Source)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findOne(SimpleJpaRepository.java:224)
...

Resources