Skip to content

Conversation

@Zerpet
Copy link
Member

@Zerpet Zerpet commented Dec 18, 2025

Following the same convention as the stream java client, our metrics are prefixed with rabbitmq.stream.. The Java client defines metrics for micrometer collector here:

https://github.com/rabbitmq/rabbitmq-stream-java-client/blob/66d7aeeef3b4a9edaf2ebc14aa31271f1dfb8f34/src/main/java/com/rabbitmq/stream/metrics/MicrometerMetricsCollector.java#L54-L65

This PR adds the same metrics to this client. Our metrics don't have the same cardinality keys (key-values associates to metrics. I would like some feedback on the current approach, specifically in the usage of a static class.

How to test the metrics

There are two options to observe the metrics. Via dotnet-counters cli tool, or via the metrics example program.

1. Via dotnet-counters

In one terminal, start a program e.g. Examples/Performances/Program.cs in one terminal:

dotnet run --project Examples/Performances/ --framework net9.0

In another terminal, run dotnet-counters:

# dotnet tool update -g dotnet-counters
dotnet-counters monitor -n Performances --counters RabbitMQ.Stream.Client

2. Via the Metrics example

This example shows how to configure an exporter for our metrics. This example uses Open Telemetry console exporter.

dotnet run --project docs/Metrics/

@Zerpet Zerpet requested a review from Gsantomaggio December 18, 2025 16:47
Copy link
Member

@Gsantomaggio Gsantomaggio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time to time there is connection numbers = -1

Image

This is important in Darwin (MacOS) because `/bin/bash` is the system
Bash, which is version 3.x. This version of bash does not recognise the
test operator `-v`, therefore the script breaks in line `if [[ -v foo]]`

With this change, `env` picks up the Bash version installed from
Homebrew (if available), which is Bash 5.x; this version has support for
`-v` operator.
This commit also has a test to demonstrate that multiple calls on
`Close()` do not decrease the counters to a negative value.

There was potential for race conditions, therefore, a basic locking
mechanism had to be introduced in the metrics class to prevent race
conditions and concurrent access.
@Zerpet Zerpet marked this pull request as ready for review December 22, 2025 14:02
@Zerpet Zerpet requested a review from Gsantomaggio December 22, 2025 15:03
Signed-off-by: Gabriele Santomaggio <[email protected]>
@Gsantomaggio Gsantomaggio merged commit 55b234b into main Dec 22, 2025
2 checks passed
@Gsantomaggio Gsantomaggio deleted the metrics branch December 22, 2025 15:31
@Gsantomaggio Gsantomaggio self-assigned this Dec 22, 2025
@Gsantomaggio Gsantomaggio added the enhancement New feature or request label Dec 22, 2025
@Gsantomaggio Gsantomaggio added this to the 1.10.0 milestone Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants