microsoft / microsoft/aspire

Kafka Consumer traces show waiting time instead of actual receiving time

Open
#8,554 3 comments 1 reaction 0 assignees View on GitHub
area-integrations kafka
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

In the official Kafka NuGet for Dotnet, the `MessageConsumer` is implemented in such a way that it has a background Thread listening for messages from Kafka.
The `MessageConsumer` itself has a blocking `Consume()` method which blocks the current thread until a message arrives on the background thread.

The `Aspire.Confluent.Kafka` package now adds tracing to this.
The problem is that the `Activity` starts just before the call to `Consume()`.
If no message is received for a long time (maybe because there just is no message in the topic), this will lead to a very long span, although nearly all of that time was just waiting and not actually receiving a message.
Whatever is coming after that is now very disproportional.

![Image](https://github.com/user-attachments/assets/70bc98f8-1de7-4b33-a042-3a11ece34f3a)

### Expected Behavior

Use the timestamp of the message itself to set the start time after it has been received this will then report the actual time the message took to travel to the consumer instead of just a long waiting time.

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version info

.NET SDK:
Version: 9.0.201
Commit: 071aaccdc2
Workload version: 9.0.200-manifests.5c4e24dc
MSBuild version: 17.13.13+1c2026462

### Anything else?

Aspire.Confluent.Kafka 9.1.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.