Skip to content

Conversation

@Zerpet
Copy link
Member

@Zerpet Zerpet commented Jan 22, 2026

This PR implements OTEL metrics for RabbitMQ Stream operations:

Metrics tracked:

  • rabbitmq.stream.connections (up/down counter)
  • rabbitmq.stream.published (counter)
  • rabbitmq.stream.confirmed (counter)
  • rabbitmq.stream.errored (counter)
  • rabbitmq.stream.chunks (counter)
  • rabbitmq.stream.chunk_size (histogram)
  • rabbitmq.stream.consumed (counter)
  • rabbitmq.stream.outstanding_publish_confirmations (up/down counter)

Implementation:

  • Add MeterProvider configuration to EnvironmentOptions
  • Instrument connection lifecycle, producer publish/confirm/error events, and consumer delivery events
  • Include OTEL semantic conventions for attributes (messaging.system, server.address, server.port, messaging.destination.name, etc.)
  • Default to noop provider when not configured

Testing:

  • Add comprehensive unit tests with mock meter provider (21 tests)
  • Add integration tests covering producer, consumer, connection, and error scenarios
  • All tests avoid OTEL SDK dependency by using custom mocks

Example:

  • Add examples/metrics demonstrating usage with stdout exporter

Running the example

To run the example, I recommend creating a Go workspace using go work as follows:

go work init
go work add .
go work add examples/metrics

This prevents the Go module from downloading the client from github, and instead use the local client code.

cd examples/metrics
go run metrics.go
# Remember to have a running rabbit

Closes: #26

Implements comprehensive OTEL metrics for RabbitMQ Stream operations:

Metrics tracked:
- rabbitmq.stream.connections (up/down counter)
- rabbitmq.stream.published (counter)
- rabbitmq.stream.confirmed (counter)
- rabbitmq.stream.errored (counter)
- rabbitmq.stream.chunks (counter)
- rabbitmq.stream.chunk_size (histogram)
- rabbitmq.stream.consumed (counter)
- rabbitmq.stream.outstanding_publish_confirmations (up/down counter)

Implementation:
- Add MeterProvider configuration to EnvironmentOptions
- Instrument connection lifecycle, producer publish/confirm/error events,
  and consumer delivery events
- Include OTEL semantic conventions for attributes (messaging.system,
  server.address, server.port, messaging.destination.name, etc.)
- Default to noop provider when not configured

Testing:
- Add comprehensive unit tests with mock meter provider (21 tests)
- Add integration tests covering producer, consumer, connection,
  and error scenarios
- All tests avoid OTEL SDK dependency by using custom mocks

Example:
- Add examples/metrics demonstrating usage with stdout exporter

This enables observability of RabbitMQ Stream operations through
standard OpenTelemetry tooling and exporters.
@Zerpet Zerpet requested a review from Gsantomaggio January 22, 2026 13:04
The default value of the metric provider is the global metric provider.
This is better because some applications simply set the metric provider
globally and do not pass it down to libraries. This approach also solves
the problem of users initialising EnvironmentOptions without the
constructor; earlier, bypassing the constuctor resulted in subsequent
panics when the metrics were initialised.
@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

❌ Patch coverage is 86.98630% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.45%. Comparing base (4d1e770) to head (4fc83ed).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pkg/stream/metrics.go 80.24% 8 Missing and 8 partials ⚠️
pkg/stream/environment.go 88.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #461      +/-   ##
==========================================
+ Coverage   83.36%   83.45%   +0.09%     
==========================================
  Files          28       29       +1     
  Lines        4238     4376     +138     
==========================================
+ Hits         3533     3652     +119     
- Misses        480      490      +10     
- Partials      225      234       +9     
Flag Coverage Δ
unittests 83.45% <86.98%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Gsantomaggio Gsantomaggio self-assigned this Jan 23, 2026
@Gsantomaggio Gsantomaggio added the enhancement New feature or request label Jan 23, 2026
@Gsantomaggio Gsantomaggio added this to the 1.7.0 milestone Jan 23, 2026
@Gsantomaggio
Copy link
Member

Please add some documentation to the README.md then we can merge! Thank you!

@Zerpet Zerpet force-pushed the feature/metrics branch 2 times, most recently from 460dc93 to ca85c9a Compare January 23, 2026 11:34
Addressing feedback in PR

Remove TODO comments in favour of #462

Related to #462

[skip ci]
Sometimes in CI this test fails because the offset is off by 1. It
passes on the next run
@Gsantomaggio Gsantomaggio merged commit dd9c5d7 into main Jan 23, 2026
7 checks passed
@Gsantomaggio Gsantomaggio deleted the feature/metrics branch January 23, 2026 13:09
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.

Add metrics

3 participants