Skip to content

Commit

Permalink
Refactor sentry-ruby.rb and add comments (#1529)
Browse files Browse the repository at this point in the history
* Refactor sentry-ruby.rb and add comments

* Update changelog
  • Loading branch information
st0012 authored Aug 12, 2021
1 parent a1f1dbc commit 8d3ce47
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
61 changes: 34 additions & 27 deletions sentry-ruby/lib/sentry-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||= {}
Expand All @@ -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?
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit 8d3ce47

Please sign in to comment.