Skip to content

refactor: event, idempotency and SSE metrics come from spans, and the last metric classes are gone - #407

Merged
HardMax71 merged 1 commit into
mainfrom
refactor/event-idempotency-sse-metrics-from-spans
Oct 19, 2026
Merged

HardMax71 merged 1 commit into
mainfrom
refactor/event-idempotency-sse-metrics-from-spans

Conversation

@HardMax71

@HardMax71 HardMax71 commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #389, the last area: the eleven instruments in EventMetrics, IdempotencyMetrics and ConnectionMetrics now come from spans, so no hand-written metric class is left. app/core/metrics keeps only setup_metrics, the OTLP MeterProvider the instrumentations use.

Changes

events.published and event.processing.duration are defined on the producer's existing publish_event span, without an error status, and the dashboards keep their event_type label. The producer now gets its tracer through the constructor instead of a module-level one. IdempotencyManager runs each check in an idempotency.check span with hit or miss and leaves spans for blocked duplicates and finished keys. The worker counts the keys in Redis every 30 s; before, both processes scanned Redis at every export. SSERedisBus leaves a span per message and per closed stream, and the API reports open streams every 10 s. BaseMetrics and MetricsProvider go, the contract test checks the span definitions only, and the queue and idempotency pages lose the stale class descriptions.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • CI/CD or tooling changes

Test Plan

  • Backend unit tests pass (cd backend && uv run pytest tests/unit)
  • Frontend unit tests pass (cd frontend && npm run test)
  • Backend E2E tests pass (docker compose exec -T backend sh -c 'uv sync --group test --no-dev --frozen --no-install-project --no-build && pytest tests/e2e')
  • Frontend E2E tests pass (cd frontend && npm run test:e2e)
  • API spec and client regenerated if routes or schemas changed (./deploy.sh openapi, then ./deploy.sh types), never edited by hand
  • Manual testing performed

Validation: unit 571 passed, contract 3 passed, e2e 489 passed and 1 skipped. After the suite, the worker's series held 263 publishes with 263 durations, 222 reserved and 222 finished keys, and 229 live keys. An SSE probe gave 2 messages, 1 closed stream and 0 open after closing.

Checklist

  • My code follows the project's style guidelines
  • I have run pre-commit run --all-files and all checks pass
  • I have added tests that prove my fix/feature works
  • I have updated documentation if needed
  • My changes don't introduce new warnings

Summary by cubic

Closes #389: the last eleven hand-written metric classes are gone. Event, idempotency, and SSE metrics now come from spans translated by the collector's signaltometrics connector, and app/core/metrics keeps only setup_metrics for the OTLP MeterProvider.

Behavior changes

  • events.published and event.processing.duration come from the producer's publish_event span; failed publishes record error spans and are not counted.
  • Idempotency checks, blocked duplicates, and finished keys each leave spans, and the worker now counts Redis keys every 30 s instead of every process scanning at export.
  • SSE messages and closed streams leave spans, and the API reports its open streams per endpoint every 10 s with zeros, replacing the in-process up-down counter.
  • The Grafana dashboard, contract test, and docs follow the new span definitions and renamed SSE labels (sse_endpoint, sse_event_type).

Written for commit 101d990. Summary will update on new commits.

View guided diff Turn on auto-fix

… last metric classes are gone

events.published and event.processing.duration are defined on the producer's existing publish_event span, which now gets its tracer through the constructor. IdempotencyManager runs each check in an idempotency.check span and leaves spans for blocked duplicates and finished keys; the worker counts the keys in Redis every 30 s instead of every process scanning Redis at each export. SSERedisBus leaves a span per message and per closed stream, and the API reports open streams every 10 s. EventMetrics, IdempotencyMetrics, ConnectionMetrics, BaseMetrics and MetricsProvider go, and app/core/metrics keeps only setup_metrics for the instrumentations. The docs on the queue and idempotency pages still described the old classes and now point at the span metrics. Closes #389.
@HardMax71
HardMax71 enabled auto-merge (squash) October 19, 2026 00:50
@coderabbitai

coderabbitai Bot commented Oct 19, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ac4f2f4b-17f9-4658-b931-1c2e093dbd88
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added documentation Improvements or additions to documentation area: execution Queue, sagas, k8s worker, pod monitor, result processor, executor pods, runtimes area: events Kafka consumers and middlewares, producer, idempotency, DLQ, replay area: realtime SSE streams and notifications area: observability Metrics, dashboards, alerts, logs, traces, OTel collector labels Oct 19, 2026
@sonarqubecloud

Copy link
Copy Markdown

@codecov-commenter

codecov-commenter commented Oct 19, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Flag Coverage Δ
backend-e2e 82.76% <91.22%> (-0.11%) ⬇️
backend-unit 74.51% <89.47%> (+0.02%) ⬆️

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

Files with missing lines Coverage Δ
backend/app/core/container.py 87.50% <ø> (ø)
backend/app/core/dishka_lifespan.py 100.00% <100.00%> (ø)
backend/app/core/metrics/__init__.py 100.00% <100.00%> (ø)
backend/app/core/metrics/base.py 68.42% <ø> (-6.58%) ⬇️
backend/app/core/providers.py 95.10% <100.00%> (-0.23%) ⬇️
backend/app/events/core/producer.py 100.00% <100.00%> (ø)
...nd/app/services/idempotency/idempotency_manager.py 90.78% <100.00%> (+0.06%) ⬆️
...ckend/app/services/idempotency/redis_repository.py 95.77% <100.00%> (+0.12%) ⬆️
backend/app/services/sse/redis_bus.py 100.00% <100.00%> (ø)
backend/app/worker.py 87.03% <100.00%> (+0.49%) ⬆️
Components Coverage Δ
Backend 92.13% <100.00%> (-0.06%) ⬇️
Frontend 92.60% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@HardMax71
HardMax71 merged commit 10f71db into main Oct 19, 2026
35 of 37 checks passed
@HardMax71
HardMax71 deleted the refactor/event-idempotency-sse-metrics-from-spans branch October 19, 2026 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: events Kafka consumers and middlewares, producer, idempotency, DLQ, replay area: execution Queue, sagas, k8s worker, pod monitor, result processor, executor pods, runtimes area: observability Metrics, dashboards, alerts, logs, traces, OTel collector area: realtime SSE streams and notifications documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metrics: replace every hand-written instrument with instrumentation, receiver and span metrics

2 participants