Skip to content

pulsar-client-instrumentation can't export receive span when call batchReceive() / batchReceiveAsync() method #12621

@coderzc

Description

@coderzc

Describe the bug

When I use batchReceive()/batchReceiveAsync() method to receive messages on pulsar-client, can't export the "receive" span.

Steps to reproduce

    public static void main(String[] args) throws PulsarClientException {
        String serviceUrl = "pulsar://localhost:6650";
        String topic = "my-topic";

        PulsarClient client = PulsarClient.builder()
                .serviceUrl(serviceUrl)
                .build();

        Consumer<String> consumer = client.newConsumer(Schema.STRING)
                .topic(topic)
                .subscriptionType(SubscriptionType.Shared)
                .subscriptionName("subs")
                .subscribe();

        Producer<String> producer = client.newProducer(Schema.STRING)
                .enableBatching(false)
                .topic(topic)
                .create();

        final int N = 1;

        for (int i = 0; i < N ; i++) {
            producer.newMessage().key("key-" + i).value("message-" + i).send();
        }

        for (int i = 0; i < N ; i++) {
            Messages<String> messages = consumer.batchReceive();
            for (Message<String> message : messages) {
                System.out.println("Received message: " + message.getValue());
                consumer.acknowledge(message);
            }
        }

        consumer.close();
        producer.close();
        client.close();
    }
java -javaagent:/path/opentelemetry-javaagent.jar \
     -Dotel.resource.attributes=service.name=myapp \
     -Dotel.traces.exporter=otlp \
     -Dotel.metrics.exporter=none \
     -jar myapp.jar

Expected behavior

Export the "receive" span when using batchReceive() method to receive messages on pulsar-client.

Actual behavior

Can't export the "receive" span

This may be related to otel.instrumentation.messaging.experimental.receive-telemetry.enabled, since when enable it, this span can be exported but traceID has changed

Javaagent or library instrumentation version

v1.32.1

Environment

JDK: JDK17
OS: macOS M1

Additional context

image image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds triageNew issue that requires triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions