diff --git a/CHANGELOG.md b/CHANGELOG.md index a9ed03078..895ee8580 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ +## 4.6.5 + - SDK should drop the event when any event processor returns nil [#1523](https://github.com/getsentry/sentry-ruby/pull/1523) - Add severity as `sentry_logger`'s breadcrumb hint [#1527](https://github.com/getsentry/sentry-ruby/pull/1527) +- Refactor `sentry-ruby.rb` and add comments [#1529](https://github.com/getsentry/sentry-ruby/pull/1529) ## 4.6.4 diff --git a/sentry-ruby/lib/sentry-ruby.rb b/sentry-ruby/lib/sentry-ruby.rb index f8033c5bc..b08a21e07 100644 --- a/sentry-ruby/lib/sentry-ruby.rb +++ b/sentry-ruby/lib/sentry-ruby.rb @@ -36,15 +36,27 @@ module Sentry THREAD_LOCAL = :sentry_hub - def self.sdk_meta - META - end + class << self + attr_accessor :background_worker - def self.utc_now - Time.now.utc - end + ##### Patch Registration ##### + # + def register_patch(&block) + registered_patches << block + end - class << self + def apply_patches(config) + registered_patches.each do |patch| + patch.call(config) + end + end + + def registered_patches + @registered_patches ||= [] + end + + ##### Integrations ##### + # # Returns a hash that contains all the integrations that have been registered to the main SDK. def integrations @integrations ||= {} @@ -55,32 +67,16 @@ def register_integration(name, version) meta = { name: "sentry.ruby.#{name}", version: version }.freeze integrations[name.to_s] = meta end - end - class << self + ##### Method Delegation ##### + # extend Forwardable def_delegators :get_current_client, :configuration, :send_event def_delegators :get_current_scope, :set_tags, :set_extras, :set_user, :set_context - attr_accessor :background_worker - - @@registered_patches = [] - - def register_patch(&block) - registered_patches << block - end - - def apply_patches(config) - registered_patches.each do |patch| - patch.call(config) - end - end - - def registered_patches - @@registered_patches - end - + ##### Main APIs ##### + # def init(&block) config = Configuration.new yield(config) if block_given? @@ -193,6 +189,9 @@ def last_event_id get_current_hub&.last_event_id end + + ##### Helpers ##### + # def sys_command(command) result = `#{command} 2>&1` rescue nil return if result.nil? || result.empty? || ($CHILD_STATUS && $CHILD_STATUS.exitstatus != 0) @@ -207,6 +206,14 @@ def initialized? def logger configuration.logger end + + def sdk_meta + META + end + + def utc_now + Time.now.utc + end end end