Skip to content

feat(yabeda): Add sentry-yabeda adapter gem#2925

Open
dingsdax wants to merge 9 commits intomasterfrom
feat/sentry-yabeda
Open

feat(yabeda): Add sentry-yabeda adapter gem#2925
dingsdax wants to merge 9 commits intomasterfrom
feat/sentry-yabeda

Conversation

@dingsdax
Copy link
Copy Markdown
Contributor

@dingsdax dingsdax commented Mar 31, 2026

Sentry Ruby gem that connects Yabeda metrics to Sentry Metrics.

What it does

  • Translates Yabeda metrics into Sentry:
    • counter ➡️ Sentry.metrics.count
    • gauge ➡️ Sentry.metrics.gauge
    • histogram / summary ➡️ Sentry.metrics.distribution
  • Adds a background worker that periodically calls Yabeda.collect!
    (needed because Yabeda is pull-based, while Sentry is push-based).
  • Provides start_collector! and stop_collector! to control this worker (must run after Sentry.init).
  • Histograms and summaries are both treated as distributions.
  • The adapter is automatically registered when required.
  • Unit handling is basic for now, with plans to improve formatting later (we don't show units in Sentry yet)

Fixes RUBY-161
Fixes #2899

Introduces sentry-yabeda, a Yabeda adapter that forwards metrics to
Sentry. Covers all four Yabeda metric types (counter, gauge, histogram,
summary), a periodic collector to drive gauge collection in push-based
environments, and a full spec suite including unit and integration tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@linear-code
Copy link
Copy Markdown

linear-code bot commented Mar 31, 2026

Endless method syntax (def m() = val) requires Ruby 3.0+. Replace with
conventional empty method bodies (def m; end) so RuboCop using the Ruby
2.7 parser does not reject the file.

Co-Authored-By: Claude Sonnet 4.6 <noreply@example.com>
@dingsdax dingsdax requested review from sl0thentr0py and solnic March 31, 2026 09:01
The app is configured as api_only but inherited from ActionController::Base,
which includes CSRF protection middleware. Switch to ActionController::API
to align with the api_only setting and eliminate the CSRF warning.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…bled

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Member

@sl0thentr0py sl0thentr0py left a comment

Choose a reason for hiding this comment

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

some cosmetics first

Copy link
Copy Markdown
Member

@sl0thentr0py sl0thentr0py left a comment

Choose a reason for hiding this comment

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

in the current start_/stop_collector model this is not very useful. Sentry generally does things automagically so the ideal design is that users just enable/add this gem and then something happens automatically, not that they have to start and stop it wherever in their code.

dingsdax and others added 5 commits April 7, 2026 15:26
The app was never referenced by any spec or CI step and carried
maintenance weight (Gemfile.lock, SQLite DB, log files). The
sentry-yabeda adapter is already covered by unit and integration
specs in sentry-yabeda/spec/.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add sentry_yabeda_test.yml following the same pattern as other gem
workflows (resque, delayed_job, opentelemetry). Wire it into tests.yml
so it runs on every PR and push to master, and is included in the
CodeCov notification gate.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace the detailed standalone sentry-yabeda README with a minimal
one matching the per-gem style used across the repo. Add sentry-yabeda
to the badge table, install snippet, and integrations list in the root
README.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Same badge table row, install snippet, and integrations list entry
as the root README — keeps the gem-level README in sync.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove the manual start_collector!/stop_collector! API. The periodic
gauge collector now starts automatically when Sentry is initialized
with enable_metrics: true, via an after(:configured) hook — consistent
with how other Sentry integrations wire into the SDK lifecycle.

Collector follows the same initialization pattern as SessionFlusher and
BackpressureMonitor, taking a configuration positional argument and
calling super(configuration.sdk_logger, interval).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dingsdax dingsdax marked this pull request as ready for review April 7, 2026 16:54
@dingsdax
Copy link
Copy Markdown
Contributor Author

dingsdax commented Apr 7, 2026

@sl0thentr0py

  • CI workflow added
  • hooked in after(:configured) instead of explicitly needed starting
  • removed app for manual testing
  • minimal README.md linking back to root README.md

@dingsdax dingsdax requested a review from sl0thentr0py April 7, 2026 16:56
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: Collector thread leaks when re-initializing with metrics disabled
    • Collector teardown is now unconditional before checking enable_metrics, and the masking spec line was removed to verify re-initialization with metrics disabled leaves no collector.

Create PR

Or push these changes by commenting:

@cursor push 6bf7f66c8d
Preview (6bf7f66c8d)
diff --git a/sentry-yabeda/lib/sentry/yabeda/configuration.rb b/sentry-yabeda/lib/sentry/yabeda/configuration.rb
--- a/sentry-yabeda/lib/sentry/yabeda/configuration.rb
+++ b/sentry-yabeda/lib/sentry/yabeda/configuration.rb
@@ -3,8 +3,10 @@
 module Sentry
   class Configuration
     after(:configured) do
+      Sentry::Yabeda.collector&.kill
+      Sentry::Yabeda.collector = nil
+
       if enable_metrics
-        Sentry::Yabeda.collector&.kill
         Sentry::Yabeda.collector = Sentry::Yabeda::Collector.new(self)
       end
     end

diff --git a/sentry-yabeda/spec/sentry/yabeda/collector_spec.rb b/sentry-yabeda/spec/sentry/yabeda/collector_spec.rb
--- a/sentry-yabeda/spec/sentry/yabeda/collector_spec.rb
+++ b/sentry-yabeda/spec/sentry/yabeda/collector_spec.rb
@@ -28,7 +28,6 @@
 
     it "does not start when enable_metrics is false" do
       Sentry.close
-      Sentry::Yabeda.collector = nil
 
       Sentry.init do |config|
         config.dsn = DUMMY_DSN

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

Reviewed by Cursor Bugbot for commit 855c165. Configure here.

Sentry::Yabeda.collector&.kill
Sentry::Yabeda.collector = Sentry::Yabeda::Collector.new(self)
end
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Collector thread leaks when re-initializing with metrics disabled

Medium Severity

The Sentry::Yabeda.collector&.kill call is inside the if enable_metrics guard, so when Sentry is re-initialized with enable_metrics = false, any previously running collector thread is never killed and leaks. The kill and nil-assignment need to happen unconditionally, before deciding whether to create a new collector. The corresponding test masks this bug by manually setting Sentry::Yabeda.collector = nil before re-initialization.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 855c165. Configure here.

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.

Yabeda adapter for Sentry Metrics

3 participants