Skip to content

Commit

Permalink
Deprecate Event#configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Jan 2, 2022
1 parent d5d045b commit 2df28fd
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions sentry-ruby/lib/sentry/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,16 @@ class Event

MAX_MESSAGE_SIZE_IN_BYTES = 1024 * 8

SKIP_INSPECTION_ATTRIBUTES = [:@configuration, :@modules, :@backtrace]
SKIP_INSPECTION_ATTRIBUTES = [:@modules, :@backtrace, :@stacktrace_builder, :@send_default_pii, :@trusted_proxies]

include CustomInspection

attr_writer(*WRITER_ATTRIBUTES)
attr_reader(*SERIALIZEABLE_ATTRIBUTES)

attr_reader :configuration, :request, :exception, :threads
attr_reader :request, :exception, :threads

def initialize(configuration:, integration_meta: nil, message: nil)
# this needs to go first because some setters rely on configuration
@configuration = configuration

# Set some simple default values
@event_id = SecureRandom.uuid.delete("-")
@timestamp = Sentry.utc_now.iso8601
Expand All @@ -48,11 +45,17 @@ def initialize(configuration:, integration_meta: nil, message: nil)

@fingerprint = []

# configuration data that's directly used by events
@server_name = configuration.server_name
@environment = configuration.environment
@release = configuration.release
@modules = configuration.gem_specs if configuration.send_modules

# configuration options to help events process data
@send_default_pii = configuration.send_default_pii
@trusted_proxies = configuration.trusted_proxies
@stacktrace_builder = configuration.stacktrace_builder

@message = (message || "").byteslice(0..MAX_MESSAGE_SIZE_IN_BYTES)

self.level = :error
Expand Down Expand Up @@ -84,6 +87,12 @@ def get_message_from_exception(event_hash)
end
end

# @deprecated This method will be removed in v5.0.0. Please just use Sentry.configuration
# @return [Configuration]
def configuration
Sentry.configuration
end

def timestamp=(time)
@timestamp = time.is_a?(Time) ? time.to_f : time
end
Expand All @@ -98,7 +107,7 @@ def rack_env=(env)

add_request_interface(env)

if configuration.send_default_pii
if @send_default_pii
user[:ip_address] = calculate_real_ip_from_rack(env)
end

Expand Down Expand Up @@ -129,7 +138,7 @@ def add_request_interface(env)
def add_threads_interface(backtrace: nil, **options)
@threads = ThreadsInterface.build(
backtrace: backtrace,
stacktrace_builder: configuration.stacktrace_builder,
stacktrace_builder: @stacktrace_builder,
**options
)
end
Expand All @@ -139,7 +148,7 @@ def add_exception_interface(exception)
@extra.merge!(exception.sentry_context)
end

@exception = Sentry::ExceptionInterface.build(exception: exception, stacktrace_builder: configuration.stacktrace_builder)
@exception = Sentry::ExceptionInterface.build(exception: exception, stacktrace_builder: @stacktrace_builder)
end

private
Expand All @@ -160,7 +169,7 @@ def calculate_real_ip_from_rack(env)
:client_ip => env["HTTP_CLIENT_IP"],
:real_ip => env["HTTP_X_REAL_IP"],
:forwarded_for => env["HTTP_X_FORWARDED_FOR"],
:trusted_proxies => configuration.trusted_proxies
:trusted_proxies => @trusted_proxies
).calculate_ip
end
end
Expand Down

0 comments on commit 2df28fd

Please sign in to comment.