openzipkin / brave

Java distributed tracing implementation compatible with Zipkin backend services.
Apache License 2.0
2.36k stars 714 forks source link

Custom Zipkin tracing for @JmsListener #915

Closed shankarwww closed 5 years ago

shankarwww commented 5 years ago

I am using spring boot 2 with dependency as:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>

My project is jms based application which receives message from a TIBCO queue, process it and then replies back to the same queue.

@JmsListener(destination = "${tibco.queue.name}")
public String onMessage(final String xmlRequest)  {
}

Request received is in xml form which contains ServiceCorrelationID in the header. The content inside ServiceCorrelationID contains the B3SingleFormat for trace and span id which is already generated by some other project.

<?xml version="1.0" encoding="UTF-8"?>
<ns0:Request>
    <ns0:Header>
        <ns1:TimeStamp>2019-04-16T11:52:49.465+02:00</ns1:TimeStamp>
        <ns1:ServiceCorrelationID>bf400f92570e67e4-c76a5a539bfd40f4-1-bf400f92570e67e4</ns1:ServiceCorrelationID>
    </ns0:Header>
    <ns0:Payload>
    </ns0:Payload>
</ns0:Request>

Requirement: What the requirement to not generate new span and trace it but use the data coming in the ServiceCorrelationID but change only span id. The incoming span will become the parent id. i.e:

incoming: bf400f92570e67e4-c76a5a539bfd40f4-1-bf400f92570e67e4 to be generated: bf400f92570e67e4-generateNewSpan-1-newParentId

How can i customize the generated span to meet my requirement ?

codefromthecrypt commented 5 years ago

this will break semantics as if you change the span ID you should usually also change the parent ID...

codefromthecrypt commented 5 years ago

actually the parent ID part is distracting in messaging as it isn't used. the header should be written with B3SingleFormat.writeB3SingleFormatWithoutParentId or similar. That way, stale parent ID isn't propagated.

To your original issue, I think you are interested in a custom propagation extractor I think.. this isn't currently supported, but we are working on a messaging abstraction and can consider this.

shankarwww commented 5 years ago

ok..i have edited my question. My main challenge is how can i keep the trace id same ?

shankarwww commented 5 years ago

actually the parent ID part is distracting in messaging as it isn't used. the header should be written with B3SingleFormat.writeB3SingleFormatWithoutParentId or similar. That way, stale parent ID isn't propagated.

To your original issue, I think you are interested in a custom propagation extractor I think.. this isn't currently supported, but we are working on a messaging abstraction and can consider this.

The challenge in my project is that the tibco jms headers cannot be changed now. Its a big change and it will impact many project. So the traceId which is originally generated by angular7 application, is passed in the payload to tibco queues. Now this message is received from the queue via @JmsListener by backend system build in spring boot 2.

codefromthecrypt commented 5 years ago

if I understand properly. what's going on is that you have a header named "ServiceCorrelationID" when it should be named "b3", and you can't change your angular apps so you prefer to change your java apps.

you will literally need to hack I think, use aop, bytebuddy or something to rename the header before the tracing JMS consumer is invoked. once the header is named properly the code should pickup the trace as you'd expect.

I'm closing this out as it isn't a feature we support, to rename header regardless of if they are http or messaging. You can look for #914 about more pluggability in messaging, which likely would help with this. However, that won't land for at least weeks. If you want to ask more questions, you can contact us on gitter. Good luck. https://gitter.im/openzipkin/zipkin