Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/sentry_yabeda_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: sentry-yabeda Test

on:
workflow_dispatch:
workflow_call:
outputs:
matrix-result:
description: "Matrix job result"
value: ${{ jobs.test.outputs.matrix-result }}
inputs:
versions:
required: true
type: string
# Cancel in progress workflows on pull_requests.
# https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
concurrency:
group: sentry-yabeda-test-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
test:
defaults:
run:
working-directory: sentry-yabeda
name: Ruby ${{ matrix.ruby_version }}, options - ${{ toJson(matrix.options) }}
runs-on: ubuntu-latest
timeout-minutes: 10
env:
RUBYOPT: ${{ matrix.options.rubyopt }}
BUNDLE_GEMFILE: ${{ github.workspace }}/sentry-yabeda/Gemfile
BUNDLE_WITHOUT: rubocop
JRUBY_OPTS: "--debug" # for more accurate test coverage
strategy:
fail-fast: false
matrix:
ruby_version: ${{ fromJson(inputs.versions) }}
include:
- ruby_version: "3.2"
options:
rubyopt: "--enable-frozen-string-literal --debug=frozen-string-literal"
exclude:
- ruby_version: 'jruby'
- ruby_version: 'jruby-head'
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4

- name: Set up Ruby ${{ matrix.ruby_version }}
uses: ruby/setup-ruby@319994f95fa847cf3fb3cd3dbe89f6dcde9f178f # v1
with:
ruby-version: ${{ matrix.ruby_version }}
bundler-cache: true

- name: Run specs
run: bundle exec rake

- name: Upload Coverage
uses: codecov/codecov-action@1af58845a975a7985b0beb0cbe6fbbb71a41dbad # v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
8 changes: 8 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ jobs:
versions: ${{ needs.ruby-versions.outputs.versions }}
secrets: inherit

yabeda-tests:
needs: ruby-versions
uses: ./.github/workflows/sentry_yabeda_test.yml
with:
versions: ${{ needs.ruby-versions.outputs.versions }}
secrets: inherit

codecov:
name: CodeCov
runs-on: ubuntu-latest
Expand All @@ -73,6 +80,7 @@ jobs:
- delayed_job-tests
- resque-tests
- opentelemetry-tests
- yabeda-tests
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4

Expand Down
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ Gemfile.lock
node_modules
.vite

.DS_Store

mise.toml

.devcontainer/.env
vendor/gems

sentry-rails/Gemfile-*.lock
mise.toml

sentry-yabeda/.DS_Store
sentry-yabeda/.rspec_status
sentry-yabeda/Gemfile-*.lock
3 changes: 3 additions & 0 deletions sentry-ruby/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Sentry SDK for Ruby
| [![Gem Version](https://img.shields.io/gem/v/sentry-delayed_job?label=sentry-delayed_job)](https://rubygems.org/gems/sentry-delayed_job) | [![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml) | [![codecov](https://codecov.io/gh/getsentry/sentry-ruby/graph/badge.svg?token=ZePzrpZFP6&component=sentry-delayed_job)](https://codecov.io/gh/getsentry/sentry-ruby) | [![API doc](https://img.shields.io/badge/API%20doc-rubydoc.info-blue)](https://www.rubydoc.info/gems/sentry-delayed_job) |
| [![Gem Version](https://img.shields.io/gem/v/sentry-resque?label=sentry-resque)](https://rubygems.org/gems/sentry-resque) | [![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml) | [![codecov](https://codecov.io/gh/getsentry/sentry-ruby/graph/badge.svg?token=ZePzrpZFP6&component=sentry-resque)](https://codecov.io/gh/getsentry/sentry-ruby) | [![API doc](https://img.shields.io/badge/API%20doc-rubydoc.info-blue)](https://www.rubydoc.info/gems/sentry-resque) |
| [![Gem Version](https://img.shields.io/gem/v/sentry-opentelemetry?label=sentry-opentelemetry)](https://rubygems.org/gems/sentry-opentelemetry) | [![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml) | [![codecov](https://codecov.io/gh/getsentry/sentry-ruby/graph/badge.svg?token=ZePzrpZFP6&component=sentry-opentelemetry)](https://codecov.io/gh/getsentry/sentry-ruby) | [![API doc](https://img.shields.io/badge/API%20doc-rubydoc.info-blue)](https://www.rubydoc.info/gems/sentry-opentelemetry) |
| [![Gem Version](https://img.shields.io/gem/v/sentry-yabeda?label=sentry-yabeda)](https://rubygems.org/gems/sentry-yabeda) | [![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml) | [![codecov](https://codecov.io/gh/getsentry/sentry-ruby/graph/badge.svg?token=ZePzrpZFP6&component=sentry-yabeda)](https://codecov.io/gh/getsentry/sentry-ruby) | [![API doc](https://img.shields.io/badge/API%20doc-rubydoc.info-blue)](https://www.rubydoc.info/gems/sentry-yabeda) |



Expand Down Expand Up @@ -53,6 +54,7 @@ gem "sentry-sidekiq"
gem "sentry-delayed_job"
gem "sentry-resque"
gem "sentry-opentelemetry"
gem "sentry-yabeda"
```

### Configuration
Expand Down Expand Up @@ -93,6 +95,7 @@ To learn more about sampling transactions, please visit the [official documentat
- [DelayedJob](https://docs.sentry.io/platforms/ruby/guides/delayed_job/)
- [Resque](https://docs.sentry.io/platforms/ruby/guides/resque/)
- [OpenTelemetry](https://docs.sentry.io/platforms/ruby/performance/instrumentation/opentelemetry/)
- [Yabeda](https://docs.sentry.io/platforms/ruby/guides/yabeda/)

### Enriching Events

Expand Down
13 changes: 13 additions & 0 deletions sentry-yabeda/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

source "https://rubygems.org"
git_source(:github) { |name| "https://github.com/#{name}.git" }

eval_gemfile "../Gemfile.dev"

# Specify your gem's dependencies in sentry-yabeda.gemspec
gemspec

gem "sentry-ruby", path: "../sentry-ruby"

gem "timecop"
21 changes: 21 additions & 0 deletions sentry-yabeda/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2020 Sentry

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
41 changes: 41 additions & 0 deletions sentry-yabeda/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<p align="center">
<a href="https://sentry.io" target="_blank" align="center">
<img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280">
</a>
<br>
</p>

# sentry-yabeda, the Yabeda integration for Sentry's Ruby client

---

[![Gem Version](https://img.shields.io/gem/v/sentry-yabeda.svg)](https://rubygems.org/gems/sentry-yabeda)
![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_yabeda_test.yml/badge.svg)
[![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master)
[![Gem](https://img.shields.io/gem/dt/sentry-yabeda.svg)](https://rubygems.org/gems/sentry-yabeda/)


[Documentation](https://docs.sentry.io/platforms/ruby/) | [Bug Tracker](https://github.com/getsentry/sentry-ruby/issues) | [Forum](https://forum.sentry.io/) | IRC: irc.freenode.net, #sentry

The official Ruby-language client and integration layer for the [Sentry](https://github.com/getsentry/sentry) error reporting API.


## Getting Started

### Install

```ruby
gem "sentry-ruby"
gem "sentry-yabeda"
```

Then initialize Sentry with metrics enabled:

```ruby
Sentry.init do |config|
config.dsn = ENV["SENTRY_DSN"]
config.enable_metrics = true
end
```

That's it! All Yabeda metrics will automatically flow to Sentry.
11 changes: 11 additions & 0 deletions sentry-yabeda/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require_relative "../lib/sentry/test/rake_tasks"

Sentry::Test::RakeTasks.define_spec_tasks(
spec_pattern: "spec/sentry/**/*_spec.rb",
spec_rspec_opts: "--order rand --format progress"
)

task default: :spec
23 changes: 23 additions & 0 deletions sentry-yabeda/lib/sentry-yabeda.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require "yabeda"
require "sentry-ruby"
require "sentry/integrable"
require "sentry/yabeda/version"
require "sentry/yabeda/adapter"
require "sentry/yabeda/collector"
require "sentry/yabeda/configuration"

module Sentry
module Yabeda
extend Sentry::Integrable

register_integration name: "yabeda", version: Sentry::Yabeda::VERSION

class << self
attr_accessor :collector
end
end
end

::Yabeda.register_adapter(:sentry, Sentry::Yabeda::Adapter.new)
79 changes: 79 additions & 0 deletions sentry-yabeda/lib/sentry/yabeda/adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# frozen_string_literal: true

require "yabeda/base_adapter"

module Sentry
module Yabeda
class Adapter < ::Yabeda::BaseAdapter
# Sentry does not require pre-registration of metrics
def register_counter!(_metric); end
def register_gauge!(_metric); end
def register_histogram!(_metric); end
def register_summary!(_metric); end

def perform_counter_increment!(counter, tags, increment)
return unless enabled?

Sentry.metrics.count(
metric_name(counter),
value: increment,
attributes: attributes_for(tags)
)
end

def perform_gauge_set!(gauge, tags, value)
return unless enabled?

Sentry.metrics.gauge(
metric_name(gauge),
value,
unit: unit_for(gauge),
attributes: attributes_for(tags)
)
end

def perform_histogram_measure!(histogram, tags, value)
return unless enabled?

Sentry.metrics.distribution(
metric_name(histogram),
value,
unit: unit_for(histogram),
attributes: attributes_for(tags)
)
end

def perform_summary_observe!(summary, tags, value)
return unless enabled?

Sentry.metrics.distribution(
metric_name(summary),
value,
unit: unit_for(summary),
attributes: attributes_for(tags)
)
end

private

def enabled?
Sentry.initialized? && Sentry.configuration.enable_metrics
end

def attributes_for(tags)
tags.empty? ? nil : tags
end

def metric_name(metric)
[metric.group, metric.name].compact.join(".")
end

# TODO: Normalize Yabeda unit symbols (e.g. :milliseconds) to Sentry's
# canonical singular strings (e.g. "millisecond") once units are visible
# in the Sentry product. See https://develop.sentry.dev/sdk/foundations/state-management/scopes/attributes/#units
def unit_for(metric)
metric.unit&.to_s
end
end
end
end
30 changes: 30 additions & 0 deletions sentry-yabeda/lib/sentry/yabeda/collector.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

require "sentry/threaded_periodic_worker"

module Sentry
module Yabeda
# Periodically calls Yabeda.collect! to trigger gauge collection blocks
# registered by plugins like yabeda-puma-plugin, yabeda-gc, and
# yabeda-gvl_metrics.
#
# In a pull-based system (Prometheus), the scrape request triggers
# collection. In a push-based system (Sentry), we need this periodic
# worker to drive the collect → gauge.set → adapter.perform_gauge_set!
# pipeline.
class Collector < Sentry::ThreadedPeriodicWorker
DEFAULT_INTERVAL = 15 # seconds

def initialize(configuration, interval: DEFAULT_INTERVAL)
super(configuration.sdk_logger, interval)
ensure_thread
end

def run
::Yabeda.collect!
rescue => e
log_warn("[Sentry::Yabeda::Collector] collection failed: #{e.message}")
end
end
end
end
12 changes: 12 additions & 0 deletions sentry-yabeda/lib/sentry/yabeda/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Sentry
class Configuration
after(:configured) do
if enable_metrics
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.

end
end
7 changes: 7 additions & 0 deletions sentry-yabeda/lib/sentry/yabeda/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module Sentry
module Yabeda
VERSION = "6.5.0"
end
end
Loading
Loading