Google Cloud Trace doesn't correlate logs from Spring Boot applications using Sleuth - spring-boot

I've recently upgraded my applications to Spring Boot 2.4.2, Cloud 2020.0.0, changing Spring Cloud GCP dependencies following the migration guide: https://googlecloudplatform.github.io/spring-cloud-gcp/2.0.0/reference/html/index.html#migration-guide-from-spring-cloud-gcp-1-x-to-2-x
Regarding the applications everything seems to be working fine. I can see calls between the microservices propagating the trace-id headers:
gateway:
2021-01-24 20:18:36.471 DEBUG [gateway,0bc6b9664e6604e2,eb9f834718fe33c9] 1 ---
service1:
2021-01-24 20:18:36.700 DEBUG [service1,0bc6b9664e6604e2,570653ac93add270,true]
In the Google Cloud Trace console I can see that the trace id (0bc6b9664e6604e2) was captured (prefixed with 16 extra 0's) and that it shows both microservices (the first post corresponds to gateway and the third call correspons to service1:
However notice the message "No logs found for this trace".
Also the Trace Logs View link complaints about it:
If I open the link it just looks by timestamp, not using the correlation trace id.
The funny thing is if I look for a log statement directly in the GCP Logging view, the trace id is there:
I can then run a GCP Logging query to find all the logs correctly:
Apparently everything seems to be OK. Could you tell why GCP Trace isn't able to correlate with GCP Logging?

For the logs to appear correlated with tracing you need to add the stackdriver log dependency (I think it only works if your log implementation is logback).
Check https://cloud.spring.io/spring-cloud-gcp/reference/html/#integration-with-logging

Related

how disable 'attempting to receive mail from folder' spring integration mail in spring boot

i need to disable "attempting to receive mail from folder " log in spring integration.
Because it writes a lot of logs in catalina.out Tomcat and increases the file size.
See more info in the issue you have raised: https://github.com/spring-projects/spring-integration/issues/3430.
This is not an INFO starting with Spring Integration version 5.4.
As a workaround you can just disable logging for the AbstractMailReceiver class making it on the, let's say, WARN level.
According your tags in the question, you probably use Spring Boot, so its configuration property for the logging may look like this:
logging.level.org.springframework.integration.mail.AbstractMailReceiver=warn
and you won't see that INFO message in logs any more.

Spring Cloud Config Client Actuator Refresh

I have a Client which listens to config server. Config Server is pointing to github. Things work fine with localhost. However when i deploy the application to Kubernetes the Client endpoint to refresh the properties doesn't work properly.
Endpoint (Post) : http://config-client.sbx.com/actuator/refresh
This returns an empty response on Postman "[]" and Response code is 200 OK. I am able to see that the Config server is up and running on K8s.
Any suggestion on what could be wrong?
P.S. I have enabled DEBUG logs but do not see much information there.
Can you verify if the application link has got the hostname and the application name when doing the refresh. Because while doing a refresh in the localhost, it will just be springboot application locally, so there wont be any need for an additional path of application-name. Wherehas when you deploy to a server normally we have to give the path name of the application in addition to the hostname. In tomcat, the URL I use is as below,
http://<hostname>/**<application-name>**/actuator/refresh/
Normally when you hit this URL via postman, it will give you a 200 response with an empty body of []. And then, you should be able to see the below lines in the log files of the client application. [ Also I had the attribute #RefreshScope attribute at the main method of the application just below the #SpringBootApplication attribute to refresh the attributes of the application.]
INFO o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment:249 - Fetching config from server at : http://<hostname>/<Config-server-application-name>/
INFO o.s.c.c.c.ConfigServicePropertySourceLocator.log:168 - Located environment: name=config-client, profiles=[development], label=null, version=ab36989c85922f1c9cf7803fac4, state=null
INFO o.s.c.b.c.PropertySourceBootstrapConfiguration.initialize:112 - Located property source: [BootstrapPropertySource {name='bootstrapProperties-configClient'}, BootstrapPropertySource {name='bootstrapProperties-https://<gitlaburl>/<companyname>/config-server.git/config-client-development.yml'}]
INFO o.s.boot.SpringApplication.logStartupProfileInfo:655 - The following profiles are active: development
INFO o.s.boot.SpringApplication.logStarted:61 - Started application in 1.557 seconds (JVM running for 70689.032)
For Kubernetes,
Try using
kubectl apply
(instead of kubectl create configmap.)
To deploy the config map, just run the following command on Kubernetes:
kubectl apply -f config-map.yml
Make sure the name of the config map matches the name of the spring boot application .Also see the below link ,
https://github.com/spring-cloud/spring-cloud-kubernetes/issues/255
Also there is a spring cloud kuberenetes which you can explore as below,
https://cloud.spring.io/spring-cloud-static/spring-cloud-kubernetes/2.0.0.M1/reference/html/#why-do-you-need-spring-cloud-kubernetes

Spring boot Zuul server logging

I just created simple Zuul Proxy at the front end for our microservices environment but now I wanted to log all the entries into the log file which went through the proxy.
Do any properly which I need to enable to do this.
I assume an implementation of zuul as a regular spring boot driven microservice with a bunch of netflix's beans running under the hood.
In this case it can run on tomcat (probably for other services the idea is the same, but the technical implementation might be different).
So for tomcat:
As a first resort you can take advantage of tomcat feature of "access logs" that logs all the requests anyway. It also allows some level of customizations (what to log). The technical difficulty is that tomcat access log is not by default managed by logback, so you'll have to use some kind of adapter.
Here you can find ideas of how to resolve this technically and integrate access log with logback.
An another approach would be creating a Filter that will extract required pieces and log the request / response / whatever you want to log
Here is an example of creating a custom filter like this.
Of course I you also need to log something from response you should configure the filter type (see the java code example in the link)
One tip / caution: think about performance implications, so that this feature won't slow down the processing if the server is under high load of requests.

When Instrumenting Zuul gateway with Jaeger, all routes marked GET

I am using Zuul as an api-gateway in a spring-cloud micro-service app, so that every access to api-gateway/some-service/a_route is redirected to /a_route in a generic way (the discovery is backed by consul).
I am trying to use Jaeger to instrument this system. And at this point I am using opentracing-spring-web-autoconfigure, because I cannot upgrade my spring boot/cloud version easily (I am using1.4.5.RELEASE Camden.SR7). So I just added the dependency, created the Jaeger tracer and redirect it to the docker all in one collector.
I have begin by instrumenting the gateway and It somewhat works => It generate span on the gateway, but all the route are marked :
apigateway-service: GET
and there is no information concerning the forwarded route at this level, the full route itself is store in a tag : http.url
"http://localhost:8080/collection-service/collections/projects/"
To be useful I would prefer to have span named :
apigateway-service: GET collection-service/collections/projects/
Can this be configured somewhere ?
No, it cannot, but it wouldn't hurt to open an issue there with this suggestion.

Spring Cloud Zipkin with RabbitMQ not persisting in MYSQL

I have done all the possible matches and mix-up of dependency and still not able to record traces in zipkin ans store it in MYSQL using RabbitMQ.
Still i can see the trace and span id's in console and nothing beyond this.
Someone please take a look at the code in github from below location.
Github code: https://github.com/javayp/distributed-tracing-1
You've mixed almost everything you could have mixed. On the app side you're using both the deprecated zipkin server and the deprecated client. On the server side you're using deprecated zipkin server.
My suggestion is that you go through the documentation https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_spring_cloud_sleuth and read that the stream servers are deprecated and you should use the openzipkin zipkin server with rabbitmq support (https://github.com/openzipkin/zipkin/tree/master/zipkin-collector/rabbitmq).
On the consumer side use https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_sleuth_with_zipkin_via_rabbitmq_or_kafka . It really is as simple as that. Also don't forget to turn on the sampling percentage to 1.0

Resources