opentracing-contrib / java-spring-cloud

Distributed tracing for Spring Boot, Cloud and other Spring projects
Apache License 2.0
388 stars 143 forks source link

Open tracing with spring cloud with Kafka, Redis, mysql initiate new span always #295

Closed chandresh-pancholi closed 4 years ago

chandresh-pancholi commented 4 years ago

Hi,

I am written spring boot application using java-spring-cloud.

Request flow

REST --> Controller --> Kafka Producer --> Kafka Consumer --> Redis Set ---> Save into MySQL DB

I am receiving two different traces

  1. Rest --> Controller --> Kafka producer--> Kafka consumer
  2. Redis set

Mysql spans are not even generating.

pavolloffay commented 4 years ago

How are you calling the redis client? If it is called in a new separate thread it might break the context propagation resulting in two traces.

cc) @malafeev could you please have a look?

chandresh-pancholi commented 4 years ago

Redis command

    private final LettuceConnectionFactory redisClusterConnection;

    public void set(String key, String value) {
        redisClusterConnection.getClusterConnection().set(key.getBytes(), value.getBytes());
    }

kafka consume

 @KafkaListener(topics = "${topic}", containerFactory = "factory", groupId = "${group.id}")
    public void activityConsume(ConsumerRecord<String, TestAvro> record) {    
        Activity activity = record.value();
        repository.save();
        redisCommand.set(String.format("%s:%s", "123", "456" ), 0);
    }
malafeev commented 4 years ago

@chandresh-pancholi how your consumer looks like? do you use @KafkaListener annotation?

chandresh-pancholi commented 4 years ago

@malafeev , I have updated the comment. please check.

malafeev commented 4 years ago

yes, it's a limitation. We don't intercept @KafkaListener annotated method to activate consumer span. It should be possible to extract span context from the record headers and then build child span of it but that's too much coding.

chandresh-pancholi commented 4 years ago

That's alright but why it only shows redis span but not mysql.

malafeev commented 4 years ago

mysql (jdbc) span should be created, but what repository.save(); is doing? Does it use MySQL JDBC driver to persist entity?

Didn't you set opentracing.spring.cloud.jdbc.withActiveSpanOnly property to true? It should be false because there is no active span.

chandresh-pancholi commented 4 years ago

Got it. Thanks @malafeev

orange-buffalo commented 4 years ago

There is a PR to implement missing support of @KafkaListener in java-kafka-client (see opentracing-contrib/java-kafka-client#83). Should we reopen this issue or create a new one to integrate a new version of java-kafka-client?