Skip to content
Merged
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
1 change: 1 addition & 0 deletions sentry-ruby/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Ignore sentry-trace when tracing is not enabled [#1308](https://github.com/getsentry/sentry-ruby/pull/1308)
- Fixes [#1307](https://github.com/getsentry/sentry-ruby/issues/1307)
- Refactor tracing implementation [#1309](https://github.com/getsentry/sentry-ruby/pull/1309)
- Allow configuring BreadcrumbBuffer's size limit [#1310](https://github.com/getsentry/sentry-ruby/pull/1310)

## 4.2.2

Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def init(&block)
config = Configuration.new
yield(config) if block_given?
client = Client.new(config)
scope = Scope.new
scope = Scope.new(breadcrumb_buffer_limit: config.breadcrumb_buffer_limit)
hub = Hub.new(client, scope)
Thread.current[THREAD_LOCAL] = hub
@main_hub = hub
Expand Down
5 changes: 3 additions & 2 deletions sentry-ruby/lib/sentry/breadcrumb_buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

module Sentry
class BreadcrumbBuffer
DEFAULT_SIZE = 100
include Enumerable

attr_accessor :buffer

def initialize(size = 100)
@buffer = Array.new(size)
def initialize(size = nil)
@buffer = Array.new(size || DEFAULT_SIZE)
end

def record(crumb)
Expand Down
4 changes: 4 additions & 0 deletions sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class Configuration
# - :active_support_logger
attr_reader :breadcrumbs_logger

# Max number of breadcrumbs a breadcrumb buffer can hold
attr_accessor :breadcrumb_buffer_limit

# Number of lines of code context to capture, or nil for none
attr_accessor :context_lines

Expand Down Expand Up @@ -172,6 +175,7 @@ class Configuration

def initialize
self.background_worker_threads = Concurrent.processor_count
self.breadcrumb_buffer_limit = BreadcrumbBuffer::DEFAULT_SIZE
self.breadcrumbs_logger = []
self.context_lines = 3
self.environment = environment_from_env
Expand Down
12 changes: 9 additions & 3 deletions sentry-ruby/lib/sentry/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class Scope

attr_reader(*ATTRIBUTES)

def initialize
def initialize(breadcrumb_buffer_limit: nil)
@breadcrumb_buffer_limit = breadcrumb_buffer_limit
set_default_value
end

Expand Down Expand Up @@ -47,7 +48,7 @@ def add_breadcrumb(breadcrumb)
end

def clear_breadcrumbs
@breadcrumbs = BreadcrumbBuffer.new
set_new_breadcrumb_buffer
end

def dup
Expand Down Expand Up @@ -171,7 +172,6 @@ def add_event_processor(&block)
private

def set_default_value
@breadcrumbs = BreadcrumbBuffer.new
@contexts = { :os => self.class.os_context, :runtime => self.class.runtime_context }
@extra = {}
@tags = {}
Expand All @@ -182,8 +182,14 @@ def set_default_value
@event_processors = []
@rack_env = {}
@span = nil
set_new_breadcrumb_buffer
end

def set_new_breadcrumb_buffer
@breadcrumbs = BreadcrumbBuffer.new(@breadcrumb_buffer_limit)
end


class << self
def os_context
@os_context ||=
Expand Down
18 changes: 18 additions & 0 deletions sentry-ruby/spec/sentry/breadcrumb_buffer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@
)
end

describe "#record" do
subject do
described_class.new(1)
end

it "doesn't exceed the size limit" do
subject.record(crumb_1)

expect(subject.buffer.size).to eq(1)

subject.record(crumb_2)

expect(subject.buffer.size).to eq(1)

expect(subject.peek).to eq(crumb_2)
end
end

describe "#to_hash" do
it "doesn't break because of 1 problematic crumb" do
subject.record(crumb_1)
Expand Down
10 changes: 10 additions & 0 deletions sentry-ruby/spec/sentry/scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
expect(subject.fingerprint).to eq([])
expect(subject.transaction_names).to eq([])
end

it "allows setting breadcrumb buffer's size limit" do
scope = described_class.new(breadcrumb_buffer_limit: 10)
expect(scope.breadcrumbs.buffer.count).to eq(10)
end
end

describe "#dup" do
Expand Down Expand Up @@ -65,6 +70,10 @@
end

describe "#clear_breadcrumbs" do
subject do
described_class.new(breadcrumb_buffer_limit: 10)
end

before do
subject.add_breadcrumb(new_breadcrumb)

Expand All @@ -75,6 +84,7 @@
subject.clear_breadcrumbs

expect(subject.breadcrumbs.empty?).to eq(true)
expect(subject.breadcrumbs.buffer.size).to eq(10)
end
end

Expand Down
9 changes: 9 additions & 0 deletions sentry-ruby/spec/sentry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
expect(subject.get_main_hub).to eq(current_hub)
end
end

it "initializes Scope with correct breadcrumb_buffer_limit" do
described_class.init do |config|
config.breadcrumb_buffer_limit = 1
end

current_scope = described_class.get_current_scope
expect(current_scope.breadcrumbs.buffer.size).to eq(1)
end
end

describe "#clone_hub_to_current_thread" do
Expand Down