Skip to content

Commit 8b7267e

Browse files
authored
Deprecate capture_exception_frame_locals in favor of include_local_variables (#1993)
1 parent 75f289d commit 8b7267e

File tree

7 files changed

+54
-14
lines changed

7 files changed

+54
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
- Fixes [#1899](https://github.com/getsentry/sentry-ruby/issues/1899)
5454
- Do not report exceptions when a Rails runner exits with `exit 0` [#1988](https://github.com/getsentry/sentry-ruby/pull/1988)
5555
56+
### Miscellaneous
57+
[
58+
- Deprecate `capture_exception_frame_locals` in favor of `include_local_variables` [#1993](https://github.com/getsentry/sentry-ruby/pull/1993)
59+
5660
## 5.7.0
5761
5862
### Features

sentry-ruby/lib/sentry-ruby.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def init(&block)
212212
nil
213213
end
214214

215-
if config.capture_exception_frame_locals
215+
if config.include_local_variables
216216
exception_locals_tp.enable
217217
end
218218

@@ -234,7 +234,7 @@ def close
234234
@session_flusher = nil
235235
end
236236

237-
if configuration&.capture_exception_frame_locals
237+
if configuration&.include_local_variables
238238
exception_locals_tp.disable
239239
end
240240

sentry-ruby/lib/sentry/configuration.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ class Configuration
9797
# @return [Array<Symbol>]
9898
attr_reader :breadcrumbs_logger
9999

100-
# Whether to capture local variables from the raised exception's frame. Default is false.
101-
# @return [Boolean]
102-
attr_accessor :capture_exception_frame_locals
103-
104100
# Max number of breadcrumbs a breadcrumb buffer can hold
105101
# @return [Integer]
106102
attr_accessor :max_breadcrumbs
@@ -140,6 +136,22 @@ class Configuration
140136
attr_accessor :inspect_exception_causes_for_exclusion
141137
alias inspect_exception_causes_for_exclusion? inspect_exception_causes_for_exclusion
142138

139+
# Whether to capture local variables from the raised exception's frame. Default is false.
140+
# @return [Boolean]
141+
attr_accessor :include_local_variables
142+
143+
# @deprecated Use {#include_local_variables} instead.
144+
alias_method :capture_exception_frame_locals, :include_local_variables
145+
146+
# @deprecated Use {#include_local_variables=} instead.
147+
def capture_exception_frame_locals=(value)
148+
log_warn <<~MSG
149+
`capture_exception_frame_locals` is now deprecated in favor of `include_local_variables`.
150+
MSG
151+
152+
self.include_local_variables = value
153+
end
154+
143155
# You may provide your own LineCache for matching paths with source files.
144156
# This may be useful if you need to get source code from places other than the disk.
145157
# @see LineCache
@@ -277,7 +289,7 @@ def initialize
277289
self.max_breadcrumbs = BreadcrumbBuffer::DEFAULT_SIZE
278290
self.breadcrumbs_logger = []
279291
self.context_lines = 3
280-
self.capture_exception_frame_locals = false
292+
self.include_local_variables = false
281293
self.environment = environment_from_env
282294
self.enabled_environments = []
283295
self.exclude_loggers = []

sentry-ruby/lib/sentry/test_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def setup_sentry_test(&block)
2525
copied_config.background_worker_threads = 0
2626

2727
# user can overwrite some of the configs, with a few exceptions like:
28-
# - capture_exception_frame_locals
28+
# - include_local_variables
2929
# - auto_session_tracking
3030
block&.call(copied_config)
3131

sentry-ruby/spec/sentry/configuration_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
require 'spec_helper'
22

33
RSpec.describe Sentry::Configuration do
4+
describe "#capture_exception_frame_locals" do
5+
it "passes/received the value to #include_local_variables" do
6+
subject.capture_exception_frame_locals = true
7+
expect(subject.include_local_variables).to eq(true)
8+
expect(subject.capture_exception_frame_locals).to eq(true)
9+
10+
subject.capture_exception_frame_locals = false
11+
expect(subject.include_local_variables).to eq(false)
12+
expect(subject.capture_exception_frame_locals).to eq(false)
13+
end
14+
15+
it "prints deprecation message when being assigned" do
16+
string_io = StringIO.new
17+
subject.logger = Logger.new(string_io)
18+
19+
subject.capture_exception_frame_locals = true
20+
21+
expect(string_io.string).to include(
22+
"WARN -- sentry: `capture_exception_frame_locals` is now deprecated in favor of `include_local_variables`."
23+
)
24+
end
25+
end
26+
427
describe "#csp_report_uri" do
528
it "returns nil if the dsn is not present" do
629
expect(subject.csp_report_uri).to eq(nil)

sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@
8282
expect(env.key?("sentry.error_event_id")).to eq(false)
8383
end
8484

85-
context "with config.capture_exception_frame_locals = true" do
85+
context "with config.include_local_variables = true" do
8686
before do
8787
perform_basic_setup do |config|
88-
config.capture_exception_frame_locals = true
88+
config.include_local_variables = true
8989
end
9090
end
9191

sentry-ruby/spec/sentry_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
expect(result).to eq(nil)
196196
end
197197

198-
context "with capture_exception_frame_locals = false (default)" do
198+
context "with include_local_variables = false (default)" do
199199
it "doens't capture local variables" do
200200
begin
201201
1/0
@@ -209,10 +209,10 @@
209209
end
210210
end
211211

212-
context "with capture_exception_frame_locals = true" do
212+
context "with include_local_variables = true" do
213213
before do
214214
perform_basic_setup do |config|
215-
config.capture_exception_frame_locals = true
215+
config.include_local_variables = true
216216
end
217217
end
218218

@@ -274,6 +274,7 @@
274274
end
275275
end
276276

277+
277278
describe ".start_transaction" do
278279
describe "sampler example" do
279280
before do
@@ -875,7 +876,7 @@
875876

876877
it "disables Tracepoint" do
877878
perform_basic_setup do |config|
878-
config.capture_exception_frame_locals = true
879+
config.include_local_variables = true
879880
end
880881

881882
expect(described_class.exception_locals_tp).to receive(:disable).and_call_original

0 commit comments

Comments
 (0)