Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable release detection when SDK is not configured to send events #1471

Merged
merged 3 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Detect release "after" SDK config is fully initialized
This allows the SDK to log release detection messages with the logger
user provides.
  • Loading branch information
st0012 committed Jun 11, 2021
commit f26895affd938b3e04d0c26250462ae9bf9a9c86
1 change: 1 addition & 0 deletions sentry-ruby/lib/sentry-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def registered_patches
def init(&block)
config = Configuration.new
yield(config) if block_given?
config.detect_release
apply_patches(config)
client = Client.new(config)
scope = Scope.new(max_breadcrumbs: config.max_breadcrumbs)
Expand Down
7 changes: 3 additions & 4 deletions sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ def initialize
self.project_root = Dir.pwd
self.propagate_traces = true

self.release = detect_release
self.sample_rate = 1.0
self.send_modules = true
self.send_default_pii = false
Expand Down Expand Up @@ -314,17 +313,17 @@ def stacktrace_builder
)
end

private

def detect_release
detect_release_from_env ||
self.release ||= detect_release_from_env ||
detect_release_from_git ||
detect_release_from_capistrano ||
detect_release_from_heroku
rescue => e
log_error("Error detecting release", e, debug: debug)
end

private

def excluded_exception?(incoming_exception)
excluded_exception_classes.any? do |excluded_exception|
matches_exception?(excluded_exception, incoming_exception)
Expand Down
15 changes: 12 additions & 3 deletions sentry-ruby/spec/sentry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,14 @@
expect(described_class.configuration.release).to eq(nil)
end

it "respects user's config" do
described_class.init do |config|
config.release = "foo"
end

expect(described_class.configuration.release).to eq("foo")
end

it 'uses `SENTRY_RELEASE` env variable' do
ENV['SENTRY_RELEASE'] = 'v1'

Expand Down Expand Up @@ -577,9 +585,11 @@
it "returns nil + logs an warning if HEROKU_SLUG_COMMIT is not set" do
string_io = StringIO.new
logger = Logger.new(string_io)
allow_any_instance_of(Sentry::Configuration).to receive(:logger).and_return(logger)

described_class.init
described_class.init do |config|
config.logger = logger
end

expect(described_class.configuration.release).to eq(nil)
expect(string_io.string).to include(Sentry::Configuration::HEROKU_DYNO_METADATA_MESSAGE)
end
Expand All @@ -600,7 +610,6 @@
it "logs the error" do
string_io = StringIO.new
logger = Logger.new(string_io)
allow_any_instance_of(Sentry::Configuration).to receive(:logger).and_return(logger)
allow_any_instance_of(Sentry::Configuration).to receive(:detect_release_from_git).and_raise(TypeError.new)

described_class.init do |config|
Expand Down