Add OpenTelemetry metrics monitor (faust[opentelemetry])#746
Open
wbarnha wants to merge 2 commits into
Open
Conversation
Add OpenTelemetryMonitor, a sensor that reports the same metric set as the Statsd and Datadog monitors through the OpenTelemetry metrics API, so Faust metrics can be exported to any OpenTelemetry-compatible backend (OTLP, Prometheus, console, ...). Faust depends only on opentelemetry-api via the new optional faust[opentelemetry] extra; every instrument is a cheap no-op until the application configures a global MeterProvider. Following OpenTelemetry conventions, each instrument is dimensioned by attributes (topic, partition, stream, table, ...) rather than baking those into the metric name as Statsd does. - faust/sensors/otel.py: OTelMetrics instrument container + OpenTelemetryMonitor. - requirements/extras/opentelemetry.txt + setup.py bundle + test requirements. - tests/unit/sensors/test_otel.py: 17 tests driving the hooks against an in-memory SDK metric reader. - docs: user-guide section, installation bundle entry, reference autodoc page. Assisted-by: Claude Opus 4.8 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LJ1voGxC8Nqs3AUPKnFVzZ
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #746 +/- ##
==========================================
+ Coverage 95.98% 96.06% +0.07%
==========================================
Files 103 104 +1
Lines 11069 11249 +180
Branches 1191 1202 +11
==========================================
+ Hits 10625 10806 +181
+ Misses 350 349 -1
Partials 94 94 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Adds a test that passes a pre-built OTelMetrics container via the `metrics=` kwarg, covering the last uncovered line/branch in OpenTelemetryMonitor.metrics (patch coverage 98.9% -> 100%). Assisted-by: Claude Opus 4.8 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LJ1voGxC8Nqs3AUPKnFVzZ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
OpenTelemetryMonitor, a sensor that reports the same metric set as the built-in Statsd and Datadog monitors, but through the OpenTelemetry metrics API — so Faust metrics can be exported to any OpenTelemetry-compatible backend (OTLP, Prometheus, the console, ...).This is the metrics counterpart to the OpenTelemetry tracing discussions in #688 / #689, and is intentionally standalone: it depends on neither of those PRs.
How it works
opentelemetry-api, via the new optionalfaust[opentelemetry]extra. Every instrument is a cheap no-op until your application configures a globalMeterProviderwith the exporter of its choice — the library never picks an SDK or exporter for you.topic,partition,stream,table,status_code, ...) rather than baking those into the metric name the way Statsd does (read_offset.{topic}.{partition}).DatadogMonitor(sameMonitorhooks, same metric coverage), so it stays consistent with the other backends and callssuper()first to preserve the in-memoryMonitorstats.Usage:
Instruments
faust.messages.received,faust.events.total,faust.messages.sent,faust.messages.send_errors,faust.table.operations,faust.assignments,faust.http.requests,faust.custom.count.faust.messages.active,faust.events.active,faust.rebalances.active,faust.rebalances.recovering.ms):faust.events.runtime,faust.commit.latency,faust.send.latency,faust.send.error_latency,faust.assignment.latency,faust.rebalance.return_latency,faust.rebalance.end_latency,faust.http.latency.faust.offset.read,faust.offset.committed,faust.offset.end,faust.producer.buffer.Changes
faust/sensors/otel.py—OTelMetricsinstrument container +OpenTelemetryMonitor.requirements/extras/opentelemetry.txt(opentelemetry-api/-sdk>=1.23.0, for the synchronousGauge), theopentelemetrybundle insetup.py, and the extra added torequirements/test.txt.tests/unit/sensors/test_otel.py— 17 tests driving theMonitorhooks against an in-memory SDK metric reader (counter/up-down/histogram/gauge points + attributes), plus the no-OpenTelemetryImproperlyConfiguredpath.docs/userguide/sensors.rst, a bundle entry indocs/includes/installation.txt, and a reference autodoc page.Verification
pytest tests/unit/sensors/— 156 passed (17 new), the full sensors suite green.black/isort/flake8(repo pins) clean on the new files.🤖 Generated with Claude Code
Generated by Claude Code