Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the tracing on the reply of a ReplyingKafkaTemplate #3808

Closed
frosiere opened this issue Mar 18, 2025 · 1 comment · Fixed by #3823
Closed

Enable the tracing on the reply of a ReplyingKafkaTemplate #3808

frosiere opened this issue Mar 18, 2025 · 1 comment · Fixed by #3823

Comments

@frosiere
Copy link
Contributor

frosiere commented Mar 18, 2025

Spring Kafka supports observation and, more specifically, tracing on Kafka templates and Kafka listeners, but tracing is not supported on the reply of a ReplyingKafkaTemplate.

As the ReplyingKafkaTemplate consumes the replies using a batch listener, it should be possible to reconstruct the tracing context (traceId and baggages) for each record when iterating over these records. This can be done by starting an observation for each record (see ReplyingKafkaTemplate#onMessage), similar as it's done in KafkaMessageListenerContainer#doInvokeRecordListener.

If we agree on this request, I could help by filing a PR.

Any help or suggestions to avoid having to handle it manually for each reply would be more than welcome.

@sobychacko
Copy link
Contributor

@frosiere That sounds like a great idea. Please feel free to send a PR addressing it. Thanks!

frosiere added a commit to frosiere/spring-kafka that referenced this issue Mar 25, 2025
frosiere added a commit to frosiere/spring-kafka that referenced this issue Mar 25, 2025
frosiere added a commit to frosiere/spring-kafka that referenced this issue Mar 26, 2025
frosiere added a commit to frosiere/spring-kafka that referenced this issue Mar 26, 2025
@artembilan artembilan added this to the 4.0.0-M2 milestone Mar 26, 2025
artembilan pushed a commit that referenced this issue Mar 26, 2025
Fixes: #3808
Issue link: #3808

Since  `ReplyingKafkaTemplate` is a `BatchMessageListener` for the provided listener container,
we cannot rely on the observation from that container.

* Implement consumer observation from the `ReplyingKafkaTemplate.BatchMessageListener`.

Signed-off-by: Francois Rosiere <[email protected]>

[[email protected] Improve commit message]

**Auto-cherry-pick to `3.2.x`**

Signed-off-by: Artem Bilan <[email protected]>
# Conflicts:
#	spring-kafka/src/test/java/org/springframework/kafka/support/micrometer/ObservationTests.java
artembilan pushed a commit that referenced this issue Mar 26, 2025
Fixes: #3808
Issue link: #3808

Since  `ReplyingKafkaTemplate` is a `BatchMessageListener` for the provided listener container,
we cannot rely on the observation from that container.

* Implement consumer observation from the `ReplyingKafkaTemplate.BatchMessageListener`.

Signed-off-by: Francois Rosiere <[email protected]>

[[email protected] Improve commit message]

Signed-off-by: Artem Bilan <[email protected]>

# Conflicts:
#	spring-kafka/src/main/java/org/springframework/kafka/core/KafkaTemplate.java
#	spring-kafka/src/test/java/org/springframework/kafka/support/micrometer/ObservationTests.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants