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

Remove verbose data from #inspect result #1602

Merged
merged 4 commits into from
Nov 8, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
This feature should only introduce negligible performance overhead in most Ruby applications. But if you notice obvious performance regression, please file an issue and we'll investigate it.

- Support `ActiveStorage` spans in tracing events [#1588](https://github.com/getsentry/sentry-ruby/pull/1588)
- Support `Sidekiq` Tags in Sentry [#1596](https://github.com/getsentry/sentry-ruby/pull/1596)

### Bug Fixes

- Connect `Sidekiq`'s transaction with its parent when possible [#1590](https://github.com/getsentry/sentry-ruby/pull/1590)
- Fixes [#1586](https://github.com/getsentry/sentry-ruby/issues/1586)
- Use nil instead of false to disable callable settings [#1594](https://github.com/getsentry/sentry-ruby/pull/1594)
- Avoid duplicated sampling on Transaction events [#1601](https://github.com/getsentry/sentry-ruby/pull/1601)
- Remove verbose data from `#inspect` result [#1602](https://github.com/getsentry/sentry-ruby/pull/1602)

### Refactoring

Expand Down
6 changes: 5 additions & 1 deletion sentry-ruby/bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "sentry/ruby"
require "sentry-ruby"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand All @@ -10,5 +10,9 @@ require "sentry/ruby"
# require "pry"
# Pry.start

# Sentry.init do |config|
# config.dsn = 'https://2fb45f003d054a7ea47feb45898f7649@o447951.ingest.sentry.io/5434472'
# end

require "irb"
IRB.start(__FILE__)
3 changes: 3 additions & 0 deletions sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "concurrent/utility/processor_counter"

require "sentry/utils/exception_cause_chain"
require 'sentry/utils/custom_inspection'
require "sentry/dsn"
require "sentry/release_detector"
require "sentry/transport/configuration"
Expand All @@ -9,6 +10,7 @@

module Sentry
class Configuration
include CustomInspection
include LoggingHelper
# Directories to be recognized as part of your app. e.g. if you
# have an `engines` dir at the root of your project, you may want
Expand Down Expand Up @@ -181,6 +183,7 @@ class Configuration

LOG_PREFIX = "** [Sentry] ".freeze
MODULE_SEPARATOR = "::".freeze
SKIP_INSPECTION_ATTRIBUTES = [:@linecache, :@stacktrace_builder]

# Post initialization callbacks are called at the end of initialization process
# allowing extending the configuration of sentry-ruby by multiple extensions
Expand Down
5 changes: 5 additions & 0 deletions sentry-ruby/lib/sentry/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'sentry/backtrace'
require 'sentry/utils/real_ip'
require 'sentry/utils/request_id'
require 'sentry/utils/custom_inspection'

module Sentry
class Event
Expand All @@ -21,6 +22,10 @@ class Event

MAX_MESSAGE_SIZE_IN_BYTES = 1024 * 8

SKIP_INSPECTION_ATTRIBUTES = [:@configuration, :@modules, :@backtrace]

include CustomInspection

attr_writer(*WRITER_ATTRIBUTES)
attr_reader(*SERIALIZEABLE_ATTRIBUTES)

Expand Down
5 changes: 5 additions & 0 deletions sentry-ruby/lib/sentry/interfaces/single_exception.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
require "sentry/utils/exception_cause_chain"

module Sentry
class SingleExceptionInterface < Interface
include CustomInspection

SKIP_INSPECTION_ATTRIBUTES = [:@stacktrace]
PROBLEMATIC_LOCAL_VALUE_REPLACEMENT = "[ignored due to error]".freeze
OMISSION_MARK = "...".freeze
MAX_LOCAL_BYTES = 1024
Expand Down
8 changes: 8 additions & 0 deletions sentry-ruby/lib/sentry/interfaces/stacktrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def to_hash
{ frames: @frames.map(&:to_hash) }
end

def inspect
@frames.map(&:to_s)
end

private

# Not actually an interface, but I want to use the same style
Expand All @@ -28,6 +32,10 @@ def initialize(project_root, line)
@filename = compute_filename
end

def to_s
"#{@filename}:#{@lineno}"
end

def compute_filename
return if abs_path.nil?

Expand Down
12 changes: 12 additions & 0 deletions sentry-ruby/lib/sentry/utils/custom_inspection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Sentry
module CustomInspection
def inspect
attr_strings = (instance_variables - self.class::SKIP_INSPECTION_ATTRIBUTES).each_with_object([]) do |attr, result|
value = instance_variable_get(attr)
result << "#{attr}=#{value.inspect}" if value
end

"#<#{self.class.name} #{attr_strings.join(", ")}>"
end
end
end
32 changes: 32 additions & 0 deletions sentry-ruby/spec/sentry/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,38 @@
end
end

describe "#inspect" do
let(:client) do
Sentry::Client.new(configuration)
end

subject do
e = begin
1/0
rescue => e
e
end

client.event_from_exception(e)
end

it "still contains relevant info" do
expect(subject.inspect).to match(/@event_id="#{subject.event_id}"/)
end

it "ignores @configuration" do
expect(subject.inspect).not_to match(/@configuration/)
end

it "ignores @modules" do
expect(subject.inspect).not_to match(/@modules/)
end

it "ignores @backtrace" do
expect(subject.inspect).not_to match(/@backtrace/)
end
end

context 'rack context specified', rack: true do
require 'stringio'

Expand Down