Apache pulsar - LoggingMetricExporter logs trace/span IDs but not getting them in log4j2 logs (Javaagent instrumentation) #17562
-
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
I completely forgot to mention, the reason I was testing with older pulsar client was because of what the reporter mentioned in this - #8859 |
Beta Was this translation helpful? Give feedback.
-
|
So I've been debugging more into the pulsar instrumentation library, and I (may be wrong but) came across some fact that the consumer span seemed to call That brought together a chain of thought that the span may be ending after message has been received in current code i.e. before the log, and if I attach a listener and then log in that listener instead of receiving manually, the consumer may still be live (I don't know if that made sense to whoever reads this). And that seemed to work. I got the trace/span Ids now.
Full sample code for reference - package org.example;
import lombok.SneakyThrows;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.pulsar.client.api.*;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
public class PulsarOtelDemoSub {
public static final String CONNURL = PulsarOtelDemoPub.CONNURL;
public static final String TOPIC = PulsarOtelDemoPub.TOPIC;
private static final Logger log = LogManager.getLogger();
@SneakyThrows
public static void main(String[] args) {
PulsarClient client = PulsarClient.builder()
.serviceUrl(CONNURL)
.build();
Consumer consumer = client.newConsumer()
.topic(TOPIC)
.subscriptionName("my-subscription")
.messageListener(new MessageListener<byte[]>() {
@Override
public void received(Consumer<byte[]> consumer, Message<byte[]> msg) {
log.info("Message received: " + new String(msg.getData(), StandardCharsets.UTF_8));
}
})
.subscribe();
}
}The bit about OpenTelemetryContextDataProvider, well I am suspecting now that's just a debugging issue. The class is present on Hope it helps out someone else. |
Beta Was this translation helpful? Give feedback.
-
|
Listener based apis work better for tracing because the message processing boundary is well define. We can extract the tracing context from the message and create a span that encompasses the listener method. Spans created inside that method will be children on the processing span created by us and the trace id propagated with the message is observable within the listener method. In contrast when you use an api like |
Beta Was this translation helpful? Give feedback.


So I've been debugging more into the pulsar instrumentation library, and I (may be wrong but) came across some fact that the consumer span seemed to call
InstrumentUtil.startAndEnd(...). Honestly the debugging has been a massive pain because classes are just not present on classpath for me to debug, and whatever I try to add, don't seem to match the bytecode, but judging by the name, it hit me that Puslar provides a listener mechanism via the messageListener.That brought together a chain of thought that the span may be ending after message has been received in current code i.e. before the log, and if I attach a listener and then log in that listener instead of receiving manually, the con…