Skip to content

feat(metrics): Fix metrics naming and add log metrics backend#270

Merged
fpacifici merged 4 commits intomainfrom
fpacifici/fix_metrics_names
Mar 17, 2026
Merged

feat(metrics): Fix metrics naming and add log metrics backend#270
fpacifici merged 4 commits intomainfrom
fpacifici/fix_metrics_names

Conversation

@fpacifici
Copy link
Copy Markdown
Collaborator

@fpacifici fpacifici commented Mar 17, 2026

Adjust metrics naming and introduce a log based metric backend.

  1. We have some issues with the metrics produced via datadog.
    1a. These are the metrics we produce sentry_streams..sentry_streams.streams.pipeline.input.message. WE are turning them into streams.pipeline.input.messages .
    1b. For the rust ones we adding streams.pipeline in front.

  2. Add a backend that prints metric values in logs periodically. This is meant to allow troubleshooting metrics production. At present we do not see any metric in prod.

Metrics naming

  • Python: use streams. prefix and suffix-only enum values (e.g. streams.input.messages) with pipeline tag.
  • Arroyo (Rust): prefix keys with streams. so arroyo.consumer.run.count becomes streams.arroyo.consumer.run.count; pipeline tag unchanged.

Log metrics backend

  • Add METRICS_PREFIX constant and LogMetricsBackend (YAML type: log, configurable period_sec) that buffers and periodically logs accumulated metrics.
  • Introduce MetricsFlusher protocol, DatadogFlusher, LogFlusher, and BufferedMetricsBackend to remove duplication between Datadog and Log backends.
  • Config schema and runner wiring for type: log; tests mock module-level logger and consolidate buffer tests.

Made with Cursor

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 17, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (metrics) Fix metrics naming and add log metrics backend by fpacifici in #270
  • Update PyO3 0.24 -> 0.28.2 for Python 3.14 support by joshuarli in #266

🤖 This preview updates automatically when you update the PR.

@fpacifici fpacifici marked this pull request as ready for review March 17, 2026 19:03
@fpacifici fpacifici requested a review from a team as a code owner March 17, 2026 19:03
Comment thread sentry_streams/src/metrics.rs Outdated
…icsBackend

Add METRICS_PREFIX constant and LogMetricsBackend that periodically
logs accumulated metrics at a configurable period (YAML type: log).

Introduce MetricsFlusher protocol, DatadogFlusher, LogFlusher, and
BufferedMetricsBackend to remove duplication between Datadog and
Log backends. Wire type=log in runner and add config schema for
log metrics (period_sec, optional tags).

Tests mock the module-level logger and patch time where needed;
merge increment/gauge/timing accumulation tests into one.

Made-with: Cursor
@fpacifici fpacifici force-pushed the fpacifici/fix_metrics_names branch from e0523fb to f5c94ea Compare March 17, 2026 19:11
Comment thread sentry_streams/sentry_streams/metrics/metrics.py Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: LogFlusher "no metrics" branch is unreachable dead code
    • Changed condition from 'if parts:' to 'if len(parts) > 1:' to properly detect when only the prefix is present without any metrics.

Create PR

Or push these changes by commenting:

@cursor push e035a18b47
Preview (e035a18b47)
diff --git a/sentry_streams/sentry_streams/metrics/metrics.py b/sentry_streams/sentry_streams/metrics/metrics.py
--- a/sentry_streams/sentry_streams/metrics/metrics.py
+++ b/sentry_streams/sentry_streams/metrics/metrics.py
@@ -189,7 +189,7 @@
         for name, value, tags in gauges:
             tags_str = " ".join(tags) if tags else ""
             parts.append(f"gauge {name.value}={value} {tags_str}".strip())
-        if parts:
+        if len(parts) > 1:
             logger.info(" | ".join(parts))
         else:
             logger.info("No metrics to flush")

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

Comment thread sentry_streams/sentry_streams/metrics/metrics.py
Comment thread sentry_streams/sentry_streams/metrics/metrics.py
@fpacifici fpacifici merged commit bcb14c8 into main Mar 17, 2026
23 checks passed
@fpacifici fpacifici deleted the fpacifici/fix_metrics_names branch March 17, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants