You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Thomas (Jira)" <ji...@apache.org> on 2021/07/22 10:11:00 UTC

[jira] [Created] (CAMEL-16815) OpenTracing with Avro Keys causes Warning

Thomas created CAMEL-16815:
------------------------------

             Summary: OpenTracing with Avro Keys causes Warning
                 Key: CAMEL-16815
                 URL: https://issues.apache.org/jira/browse/CAMEL-16815
             Project: Camel
          Issue Type: Bug
          Components: camel-opentracing
            Reporter: Thomas


I am writing an event to Kafka. The key and value are both written in Avro format (same entity used). Code is like:
{code:java}
// invokation: curl -H "Content-Type: application/json" -X POST -d '{"id": "1", "message": "some message text"}' localhost:8080/event
from(platformHttp("/event").httpMethodRestrict(HttpMethod.POST))
                .log("Start")
                .unmarshal().json(JsonLibrary.Jackson, AvroEntry.class)

                // set avro header
                .process(exchange -> {
                    exchange.getIn().setHeader(KafkaConstants.KEY, new AvroEntry(1L, "header"));
                })

                .to(kafka("{{kafka.to.topic}}")
                    .brokers("{{kafka.bootstrap.servers}}")
                    .securityProtocol("{{kafka.security.protocol}}")
                    .sslContextParameters(getSslContext())
                    .sslKeystoreType("{{kafka.ssl.keystore.type}}")
                    .sslTruststoreType("{{kafka.ssl.truststore.type}}")
                    .schemaRegistryURL("{{schema.registry.url}}")
                    .valueSerializer("{{kafka.value.serializer}}")
                    .keySerializer("{{kafka.key.serializer}}"))

                // Set response for invoker
                .setBody(constant("{\"message\": \"done\"}"))
                .log("End");
{code}
When OpenTracing is included, the following warning is shown:
{code:java}
2021-07-19 14:53:39,648 WARN  [org.apa.cam.tra.Tracer] (vert.x-worker-thread-1) Tracing: Failed to capture tracing data: java.lang.ClassCastException: class com.example.model.AvroEntry cannot be cast to class java.lang.String (com.example.model.AvroEntry is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @46dd830d; java.lang.String is in module java.base of loader 'bootstrap')
        at org.apache.camel.tracing.decorators.KafkaSpanDecorator.pre(KafkaSpanDecorator.java:75)
        at org.apache.camel.tracing.Tracer$TracingEventNotifier.notify(Tracer.java:246)
        at org.apache.camel.support.EventHelper.doNotifyEvent(EventHelper.java:1240)
        at org.apache.camel.support.EventHelper.notifyExchangeSending(EventHelper.java:704)
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:140)
        at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:395)
        at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:148)
        at org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:60)
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:147)
        at org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:312)
        at org.apache.camel.component.platform.http.vertx.VertxPlatformHttpConsumer.lambda$handleRequest$2(VertxPlatformHttpConsumer.java:184)
        at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$2(ContextImpl.java:313)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:829)
{code}
This comprehensive warning is written for every message.

 

However, the message is still written to Kafka. Seems like the tracer can not handle a non-string Key ([https://github.com/apache/camel/blob/80b92e3624ae5db59a1a24a441f1b10b39eaa1a5/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/KafkaSpanDecorator.java#L75]). 

Furthermore, when using Avro format as message key, the {{uber-trace-id}} in the message headers is missing. See the comparision (kafkacat extract):
{code:java}
// When using no key
Topic: avro-topic
   Key (-1 bytes):
   Value (24 bytes): "some message text
   Headers: Accept=*/*,Content-Length=43,Content-Type=application/json,Host=localhost:8080,uber-trace-id=a5c968dea6f3d52c:bfdfb86ec15171db:a5c968dea6f3d52c:0,User-Agent=curl/7.71.1
   Timestamp: 1626696278639
   Partition: 0
   Offset: 0

// When using Avro key (no trace info)
Topic: avro-topic
   Key (13 bytes): header
   Value (24 bytes): "some message text
   Headers: Accept=*/*,Content-Length=43,Content-Type=application/json,Host=localhost:8080,User-Agent=curl/7.71.1
   Timestamp: 1626696849111
   Partition: 0
   Offset: 1
{code}
See also [this|https://camel.zulipchat.com/#narrow/stream/257298-camel/topic/OpenTracing.20with.20Avro.20Keys.20causes.20Warning] discussion on zulip. 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)