Traces not propagating to GCP Cloud Trace from spring boot application - spring-boot

I have a spring boot microservice which consumes and publishes messages from/to PubSub and is deployed on GKE. I am using spring stream binder for pubsub integration and Cloud Sleuth for generating traceId and spanId. TraceId and spanId are propagated to Stackdriver logging.
Now I want to send the trace data to Cloud trace. As per Spring GCP trace documentation, I have added gcp trace starter dependency but trace data are not being sent to Cloud trace.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-trace</artifactId>
</dependency>
I also tried adding this property spring.cloud.gcp.trace.enabled=true. Application is not throwing an error/exception. Am I missing something in configuration and how can I debug this issue? Any help would be appreciated.

Related

Zipkin export flag is not getting printed in the Spring Boot Application logs

`I am implementing sleuth and zipkin locally and getting the following issue:
zipkin export flag of sleuth is not getting printed at all in the service logs. Only application name, trace id and span id is coming as shown bellow:
INFO [sleuthpoc,a3b11678e089f17b,a3b11678e089f17b]
My bootstrap.properties is:
spring.zipkin.base-url=(http://localhost:9411/)
spring.sleuth.sampler.probability=1
Spring Cloud version: 2021.0.4
Spring Boot version: 2.7.5
Java version: 17
Is there is any property that I am missing here as I am not able to see the service trace in the zipkin server because information is not sent to zipkin because of this issue.
Trying locally and expecting to see the zipkin export flag in logs and service request trace in zipkin server`
AFAIR We've stopped printing it starting with Spring Cloud 2021.0.0. It's not being put to MDC anymore.

TraceId missing when logging #SqsListener

In my spring boot project, TraceId missing only inside #SqsListener annotated method.
I have used spring-cloud-starter-sleuth for logging and logback configuration.
Which sleuth version are you using? They removed SQS support since 3.0 release. https://github.com/spring-cloud/spring-cloud-sleuth/issues/1876.
This repo can be helpful in implementing putting traces into SQS messages but getting them from the message and injecting into MDC you need to implement on your own.

Do we need to use Sleuth with Zipkin

In order to trace service invocation across microservices , we can use Zipkin.
From the below URLs ,we understand the time taken for calls across micro services can be captured in zipkin
https://tanzu.vmware.com/developer/guides/spring/spring-zipkin/
https://springhow.com/spring-boot-zipkin-distributed-tracing/
Do we still need to use spring sleuth along with zipkin ? Does the span id and trace id generated by Sletuh provide any additional information apart from what Zipkin can capture on its own ?
Since brave is a zipkin library I presume there is no need to have dependency on sleuth in order to trace service calls across microservices.
One probable benefit of Sleuth is that it adds the span id and trace id in the application logs ( using logback MDC concept ) . These logs can be pushed into elastic search using Logstash
If you want to use only Spring Cloud Sleuth without the Zipkin integration, add the spring-cloud-starter-sleuth module to your project
Check this for reference

How do implementations like Spring Cloud Sleuth are made?

By adding Spring Cloud Sleuth as a dependency in my Spring Boot project the logging mask, like magic, changes.
The change that happens is the inclusion of the traceId, spanId and applicationName in the informations that are logged when I do log.info(...) and other logging commands.
How do Spring Cloud Sleuth does that? Is that a appender implementation? Do a programatically change happens in the log mask to be able to print it when Spring Boot auto-configuration is started?

Spring cloud sleuth with Spring data jpa

We are trying to implement Spring cloud sleuth with Zipkin in our project and wanted to know if Spring cloud sleuth will support DB calls with Spring data JPA.
I want to trace the time taken for DB calls just like service calls
When I make a service call with RestTemplate, that gets sent to zipkin and I am able to see that on the dashboard
But DB interactions with Spring data jpa is not getting displayed in Zipkin
You can use the new Dalston feature of using annotations on Spring Data repositories. You can check out this for more info http://cloud.spring.io/spring-cloud-sleuth/spring-cloud-sleuth.html#_managing_spans_with_annotations

Resources