Skip to content

Commit

Permalink
Merge pull request #689 from bugsnag/breadcrumbs-getter
Browse files Browse the repository at this point in the history
Add `Bugsnag#breadcrumbs` getter
  • Loading branch information
imjoehaines committed Aug 26, 2021
2 parents 50759dd + 36a0fa4 commit 394311a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,8 @@ Changelog
* Add `context` attribute to configuration, which will be used as the default context for events. Using this option will disable automatic context setting
| [#687](https://github.com/bugsnag/bugsnag-ruby/pull/687)
| [#688](https://github.com/bugsnag/bugsnag-ruby/pull/688)
* Add `Bugsnag#breadcrumbs` getter to fetch the current list of breadcrumbs
| [#689](https://github.com/bugsnag/bugsnag-ruby/pull/689)

### Fixes

Expand Down
11 changes: 11 additions & 0 deletions lib/bugsnag.rb
Expand Up @@ -326,6 +326,17 @@ def remove_on_breadcrumb(callback)
configuration.remove_on_breadcrumb(callback)
end

##
# Returns the current list of breadcrumbs
#
# This is a per-thread circular buffer, containing at most 'max_breadcrumbs'
# breadcrumbs
#
# @return [Bugsnag::Utility::CircularBuffer]
def breadcrumbs
configuration.breadcrumbs
end

##
# Returns the client's Cleaner object, or creates one if not yet created.
#
Expand Down
7 changes: 5 additions & 2 deletions lib/bugsnag/configuration.rb
Expand Up @@ -449,9 +449,12 @@ def max_breadcrumbs=(new_max_breadcrumbs)
end

##
# Returns the breadcrumb circular buffer
# Returns the current list of breadcrumbs
#
# @return [Bugsnag::Utility::CircularBuffer] a thread based circular buffer containing breadcrumbs
# This is a per-thread circular buffer, containing at most 'max_breadcrumbs'
# breadcrumbs
#
# @return [Bugsnag::Utility::CircularBuffer]
def breadcrumbs
request_data[:breadcrumbs] ||= Bugsnag::Utility::CircularBuffer.new(@max_breadcrumbs)
end
Expand Down
6 changes: 6 additions & 0 deletions spec/bugsnag_spec.rb
Expand Up @@ -521,4 +521,10 @@ module Kernel
}
end
end

describe "#breadcrumbs" do
it "returns the configuration's breadcrumb buffer" do
expect(Bugsnag.breadcrumbs).to be(Bugsnag.configuration.breadcrumbs)
end
end
end

0 comments on commit 394311a

Please sign in to comment.