Skip to content

Kafka batch mode breaks traceId continuity between producer and processor spans #14166

Open
@mznet

Description

@mznet

Describe the bug

When using Kafka in batch mode, I observed that producer and processor spans are not tied together with the same traceId. However, when in single-record mode, spans are correctly linked under a shared trace context.

This result makes it difficult to achieve proper end-to-end traceability when processing messages in batches — which is a common practice in performance-sensitive systems.

Image

This image shows the result of a test on a sample application

Steps to reproduce

  1. Configure a @KafkaListener with a ConcurrentKafkaListenerContainerFactory bean.
  2. Enable batch mode via:
factory.setBatchListener(true);

Expected behavior

Producer and process spans should be tied together with the shared trace context to make proper end-to-end observability as soon as possible.

Actual behavior

  • On batch mode, producer and process are not tied together with one traceId, having different trace context.
  • On single record mode, produce and process are tied together with one traceId.

Javaagent or library instrumentation version

v2.17.0

Environment

JDK: Eclipse Temurin 21.0.6
OS: Mac OS 15.3.1 (24D70)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds author feedbackWaiting for additional feedback from the authorneeds 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